Lock and Unlock Your Keychain from the Terminal

Manually lock the login keychain with security lock-keychain so no app can read saved passwords until it is unlocked.

macOSpasswordsKeychainsecurityMedium risk
Run `security lock-keychain ~/Library/Keychains/login.keychain-db` to lock it; unlock again with `security unlock-keychain ~/Library/Keychains/login.keychain-db` (it prompts for your password).

01Command

Command
$ security lock-keychain ~/Library/Keychains/login.keychain-db

02What it does

While the login keychain is locked, any app that wants a stored password must trigger a prompt rather than reading it silently — a cheap extra guard when handing over the Mac briefly or leaving it logged in. Locking does not log you out and does not touch the items themselves. The default keychain can also be locked with `security lock-keychain -u`.

03Risk

RiskMedium risk
RequirementsUnlocking will prompt for your login password; apps then ask for the keychain password on next access.
!Warning: Once locked, every app needing a saved password will prompt again until the keychain is unlocked.

04Undo

Undo
$ security unlock-keychain ~/Library/Keychains/login.keychain-db

05Sources

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

06Related solutions