Set Keychain Auto-Lock with security set-keychain-settings
Make saved passwords lock on sleep and after an idle timeout instead of staying open all day.
01Command
$ security set-keychain-settings -l -t 900 ~/Library/Keychains/login.keychain-db02What it does
By default the login keychain unlocks once at login and stays open until logout. set-keychain-settings changes that: -l locks the keychain whenever the Mac sleeps, and -t seconds adds an inactivity timeout. Check the current behavior first with security show-keychain-info, then pick a timeout that balances safety against password prompts.
03Risk
04Undo
$ security show-keychain-info ~/Library/Keychains/login.keychain-db # shows current auto-lock settings05Sources
- security - keychain command line interfaceEvidence: Documents set-keychain-settings with -l (lock on sleep) and -t (auto-lock timeout in seconds).
Last verified: 2026-09-18 · Category: Security & Privacy
06Related solutions
Build an AES-256 encrypted .dmg vault from the Terminal — no Disk Utility clicking required.
Check whether an application bundle was signed properly and hasn't been modified since.
Snapshot an entire app's settings to a plist file, then restore or migrate it later.