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.
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" -w02What 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
!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
- security — Keychain and CMS command interface (macOS)Evidence: Documents find-generic-password with -s (service), -a (account) and -w (write password to stdout).
Last verified: 2026-09-17 · Category: Security & Privacy