3

This question already has an answer here:

I have activated the Keychain Menu Bar icon so I can relatively easily click Lock Screen to lock the screen of my MacBook.
Is there a way to do this with a shortcut or via the command line? I know you can lock the keychain via the commmand line, but I cannot seem to find the how to lock the screen as well.

marked as duplicate by klanomath, grg osx Apr 26 '15 at 9:14

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

3

Open Terminal and enter the following in a single line:

/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspend

There isn’t any confirmation, the desktop is immediately locked and the lock screen appears regardless of what is currently going on with the active user account.

The menu item being used is the same Fast User Switching menu that displays a user name in the upper right corner, and the lock screen shown is identical to what is summoned if one were to select “Login Window…” from that same menu.

You can lock a screen using a keyboard shortcut as well, but using the command line offers two obvious advantages; it can be included within scripts or entered from SSH to remotely lock a Mac.

Source : Lock the Mac Desktop from the Command Line

  • 1
    Doesn't work on recent versions, logs out the user instead. – Devesh Khandelwal Apr 27 '17 at 7:35

Not the answer you're looking for? Browse other questions tagged .