Read a Password from Keychain with security find-generic-password

Look up app passwords stored in the macOS Keychain from the command line instead of opening Keychain Access.

macOSpasswordsKeychainsecurityMedium risk
Run `security find-generic-password -s "MyService" -w` to print the password stored for that service to the terminal.

01Command

Command
$ security find-generic-password -s "MyService" -w

02What it does

The security utility is the command-line interface to the Keychain. find-generic-password matches items by service (-s), account (-a), or both; the -w flag prints the actual secret instead of the item metadata. Drop -w to inspect attributes like creation date and access control. This is the standard trick for scripts that need a credential without hardcoding it.

03Risk

RiskMedium risk
RequirementsBuilt-in on macOS; the Keychain item must exist and (on first access) you must approve the prompt.
!Warning: The password appears in plain text and may be captured in shell history or logs; avoid running it in shared sessions.

04Undo

✓No undo needed — this command does not change persistent state.

05Sources

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

06Related solutions