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.

macOSsessionlockscreensecurityLow risk
Run pmset displaysleepnow to put the display to sleep immediately and trigger the lock screen.

01Command

Command
$ pmset displaysleepnow

02What 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

RiskLow risk
RequirementsWorks fully when 'Require password after sleep or screen saver' is enabled in System Settings → Lock Screen.
!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

Last verified: 2026-09-18 · Category: Security & Privacy

06Related solutions