A passphrase set with ssh-keygen encrypts the private key on disk, so anyone who copies the file cannot use it without the phrase. You add or change it with ssh-keygen -p, slow down brute-force attempts with -a (more key derivation rounds) and type it once per session by loading the key into ssh-agent with ssh-add.
Creating an Ed25519 key with a passphrase and -a rounds in ssh-keygen
OpenSSH has supported Ed25519 keys since version 6.5 (January 2014), so any reasonably current server accepts them. This command creates a new key and asks for the passphrase twice without echoing it:
ssh-keygen -t ed25519 -a 100 -C "admin@laptop" -f ~/.ssh/id_ed25519-t ed25519: key type.-a 100: rounds of the key derivation function (KDF) that turns the passphrase into the key encrypting the file. More rounds make every brute-force guess slower, and every legitimate unlock too.-C: comment shown inauthorized_keysand in the output ofssh-add -l.-f: path of the private key file; the public key lands inid_ed25519.pub.
Without a passphrase, the private key is a plaintext file: a backup, a synced folder or a stolen laptop hands over access to every server that trusts it. With a passphrase, a stolen file is only good for an offline attack whose cost depends on the strength of the phrase and the -a value. Every option is described in the ssh-keygen manual page.
Adding or changing the passphrase on an existing key with ssh-keygen -p
ssh-keygen -p re-encrypts the private key with a new passphrase and leaves the public key untouched, so authorized_keys on your servers needs no changes.
# Add or change the passphrase (asks for the current one, if any, then the new one twice)
ssh-keygen -p -f ~/.ssh/id_ed25519
# Change it and set the derivation rounds at the same time
ssh-keygen -p -a 100 -f ~/.ssh/id_ed25519
# Check you remember the passphrase: prints the public key if it is correct
ssh-keygen -y -f ~/.ssh/id_ed25519
# Expected permissions
chmod 700 ~/.ssh
chmod 600 ~/.ssh/id_ed25519 ~/.ssh/authorized_keysThe same procedure fixes an old key generated with -N "": ssh-keygen -p asks for a new phrase and the key stops being plaintext. The -P (old passphrase) and -N (new passphrase) flags make it non-interactive, but they leave the phrase in your shell history and the process list; in an interactive terminal, let ssh-keygen prompt for it.
Loading the key into ssh-agent with ssh-add to type the passphrase once
ssh-agent holds the decrypted key in memory and ssh-add hands it over after asking for the passphrase once; from then on ssh, scp and sftp sign through the agent.
# Start the agent in the current shell (if the system does not already)
eval "$(ssh-agent -s)"
# Load the key; prompts for the passphrase
ssh-add ~/.ssh/id_ed25519
# Load it for one hour only
ssh-add -t 3600 ~/.ssh/id_ed25519
# Require confirmation every time it is used
ssh-add -c ~/.ssh/id_ed25519
# List loaded fingerprints, remove one key or empty the agent
ssh-add -l
ssh-add -d ~/.ssh/id_ed25519
ssh-add -DTo skip running ssh-add by hand, AddKeysToAgent yes in ~/.ssh/config adds the key to the agent the first time ssh unlocks it:
Host *
AddKeysToAgent yes
IdentityFile ~/.ssh/id_ed25519ssh-add -c needs a confirmation program (askpass) available on the desktop; without one, signing fails. The full option list is in the official ssh-add manual.
Passphrase and ssh-agent on desktop vs SSH keys on iOS and Android with termi1
termi1 generates the SSH key on the phone itself and stores it in the system's secure storage; the private key never leaves the device and is never sent to termi1 servers.
| What is compared | Desktop with OpenSSH | termi1 on iOS and Android |
|---|---|---|
| Where the private key lives | File in ~/.ssh with 600 permissions | Operating system secure storage |
| How it is generated | ssh-keygen -t ed25519 -a 100 | On the phone itself, inside the app |
| Protection of the key at rest | Passphrase encryption with -a rounds | Secure storage; the key never leaves the device |
| Installing the public key | ssh-copy-id or editing authorized_keys | On a Mac, termi1 Companion with a six-digit code |
| Who can reach the key | Processes with access to the file or agent | Nobody outside the device; not the AI either |
You can also manage the keys that live on your servers from the phone. termi1's keyboard has Tab to complete paths like ~/.ssh/id_ed25519 and Ctrl to abort a half-finished ssh-keygen -p with Ctrl+C. The AI can type ssh-add -l or ssh-keygen -p -f ~/.ssh/id_ed25519 into the prompt from a sentence; in Review mode it never presses Enter, and you always type the passphrase yourself, because the AI never receives keys or passwords.
5 mistakes when protecting a private key with an ssh-keygen passphrase
- Putting the passphrase on the command line.
-Nand-Pleave it in your shell history. - Leaving permissions too open. ssh refuses a private key readable by other users; fix it with
chmod 600on the key andchmod 700 ~/.ssh. - Keeping keys in the agent forever. A key loaded in the agent of an unlocked laptop is as good as a key without a passphrase; use
ssh-add -tand runssh-add -Dwhen you finish. - Setting
ForwardAgent yesunderHost *. Anyone with root on the remote server can use the agent socket while your session lasts; enable it per host and only on machines you control. - Confusing the passphrase with the server password. The passphrase decrypts the local file and never crosses the network; changing it does not affect the remote account.
If you would rather carry your keys in your pocket, see the SSH terminal for your phone or get termi1 on the App Store.
Frequently asked questions
How do I remove the passphrase from an SSH key?
You remove the passphrase from an SSH key with ssh-keygen -p -f ~/.ssh/id_ed25519, entering the current one and leaving the new one empty twice. The file becomes plaintext, so this only makes sense for service accounts with 600 permissions and tightly restricted access on the server.
Does changing the passphrase require updating authorized_keys?
Changing the passphrase with ssh-keygen -p does not require updating authorized_keys, because the public key stays the same: only the local private file is re-encrypted. Servers keep accepting the same key. If the key may have leaked, the right move is generating a new one and removing the old.
How many -a rounds should I use with ssh-keygen?
The number of ssh-keygen -a rounds is a trade-off: more rounds make each brute-force guess more expensive and each unlock slower. Try a value such as 100, time ssh-keygen -y on your slowest machine and raise it while the delay stays acceptable.
Does ssh-agent store the passphrase on disk?
ssh-agent does not store the passphrase on disk: it keeps the decrypted private key in memory for as long as the agent runs. That is why you should limit each key's lifetime with ssh-add -t, empty the agent with ssh-add -D and avoid forwarding it to servers you do not control.