Lock Your Mac Screen Instantly from the Command Line
Sleep the display on demand so the password prompt appears — the fast way to secure your Mac when leaving.
Run pmset displaysleepnow to put the display to sleep immediately and trigger the lock screen.
01Command
Command
$ pmset displaysleepnow02What it does
macOS has no single 'lock' binary, but pmset displaysleepnow puts the display to sleep at once, and with 'Require password after sleep' enabled that is exactly the lock screen. For older setups the classic CGSession command ('/System/Library/CoreServices/Menu Extras/User.menu/Contents/Resources/CGSession' -suspend) suspends the session directly. Both bind neatly to a hotkey via Automator or a shell alias.
03Risk
!Warning: If 'Require password after sleep or screen saver' is set to 'never', the Mac wakes straight to the desktop with no password — enable it in System Settings → Lock Screen for this to be a real lock.
04Undo
✓No undo needed — this command does not change persistent state.
05Sources
- Set your Mac to automatically log out after a period of inactivityEvidence: Covers macOS lock-screen and password-requirement settings that make display sleep secure the session.
- pmset - power management settingsEvidence: Documents pmset displaysleepnow for putting displays to sleep immediately from the command line.
Last verified: 2026-09-18 · Category: Security & Privacy