Store Your SSH Passphrase in the macOS Keychain
Apple's ssh-add has a macOS-specific flag, --apple-use-keychain, that remembers passphrases so ssh-agent can load keys automatically.
Run `ssh-add --apple-use-keychain ~/.ssh/id_ed25519` once to save the passphrase to the keychain.
01Command
Command
$ ssh-add --apple-use-keychain ~/.ssh/id_ed2551902What it does
This flag exists only in Apple's shipped ssh-add and is easy to forget because generic OpenSSH documentation never mentions it. Once stored, passphrases survive reboots: ssh-agent reads them from the keychain the first time the key is used, provided ~/.ssh/config contains `UseKeychain yes` and `AddKeysToAgent yes`. Note the old short form -K was deprecated in favor of the long flag, and ssh-add -D removes loaded keys (but not the keychain entry).
03Risk
!Warning: The passphrase lives in the login keychain — anyone unlocked into your user session can use it.
04Undo
Undo
$ ssh-add -D && ssh-add --apple-use-keychain ~/.ssh/id_ed25519 (re-add without passphrase by regenerating the key)05Sources
- ssh-add(1) — macOS man pageEvidence: Documents --apple-use-keychain: the passphrase is added to the keychain and later loaded automatically by ssh-agent.
- ssh-add(1) — macOS man pageEvidence: Apple's ssh-add variant supports --apple-use-keychain (formerly -K) to persist passphrases in the macOS keychain.
Last verified: 2026-09-17 · Category: Security & Privacy