Put computer to sleep and have it ask for password on wake 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.



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'