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.
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-db02What 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
!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-db05Sources
- security — administer Keychains and key items (macOS man page)Evidence: Documents `security lock-keychain [-u|keychain]` and `unlock-keychain` for manually locking and unlocking a keychain.
Last verified: 2026-09-18 · Category: Security & Privacy