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.

macOSKeychainsecuritysettingsMedium risk
Run security set-keychain-settings -l -t 900 ~/Library/Keychains/login.keychain-db to lock on sleep and after 15 idle minutes.

01Command

Command
$ security set-keychain-settings -l -t 900 ~/Library/Keychains/login.keychain-db

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

RiskMedium risk
!Warning: Shorter timeouts mean more prompts for Safari passwords, mail accounts, and saved Wi-Fi — too aggressive and you'll train yourself to retype constantly. Changing the login keychain's settings is saved immediately and cannot be undone with a single flag.

04Undo

Undo
$ security show-keychain-info ~/Library/Keychains/login.keychain-db   # shows current auto-lock settings

05Sources

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

06Related solutions