How do I put computer to sleep and have it re-awake asking for a password?

I'm looking for a terminal command to do this.

I tried pmset sleepnow did not work.


There are multiple answers to the question of how to programmatically enable 'Ask for password after sleep or screensaver' -- the option that appears in the Security preferences panel.

enter image description here

Once you've enabled that option, you can use the following command to run an AppleScript to sleep the computer:

osascript -e 'tell application "Finder" to sleep'

You must log in to answer this question.

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