ssh-add Load a key into the agent and save it in the Keychain
Gives your key to ssh-agent, the background helper macOS runs for you, so ssh can use it without asking for the passphrase each time. With the Keychain option, the passphrase is also stored in macOS so the key reloads itself after a restart.
Synopsis
ssh-add [OPTION]... [FILE]...
Common options
| Option or form | What it does |
|---|---|
--apple-use-keychain | Save the passphrase in the macOS Keychain as well as loading the key. This is the macOS spelling; older guides use -K |
-l | List the keys the agent currently holds |
-L | List the public keys of the loaded keys in full |
-d FILE | Remove one key from the agent |
-D | Remove every key from the agent |
-t SECONDS | Forget the key from the agent after this many seconds |
Examples
ssh-add --apple-use-keychain ~/.ssh/id_ed25519
Enter passphrase for /Users/you/.ssh/id_ed25519:
Identity added: /Users/you/.ssh/id_ed25519 (bob@google.com)
ssh-add -l
256 SHA256:Vq0n...x9Ac bob@google.com (ED25519)
ssh-add -t 3600 ~/.ssh/id_ed25519_nas
ssh-add -D
Notes
- Loading a key once is not enough on its own: add AddKeysToAgent yes and UseKeychain yes to ~/.ssh/config (see ssh-config) so each key reloads after a restart with no extra command.
- "Could not open a connection to your authentication agent" means no agent is running in that shell. On macOS this normally does not happen in Terminal.
- -d only removes the key from the agent. The Keychain entry and the key file stay.
- To forget a stored passphrase entirely, delete the entry in the Keychain Access app (search for ssh).
See also
Last reviewed 2026-10-12.