SSH key passphrases
A passphrase encrypts the private key file. It does not protect a compromised running machine, but it makes a stolen copy useless.
What it protects
A passphrase encrypts the private key file. It is independent of the server, the account and the session:
| Passphrase | Server password | |
|---|---|---|
| Where it lives | On your machine, in the key file | On the server, hashed in shadow |
| Sent over the network | Never | Yes, over the encrypted channel |
| What fails when it is wrong | The file cannot be unlocked | You cannot log in |
| What a stolen copy means | Useless without the passphrase | Not applicable |
| How you change it | ssh-keygen -p -f <key> |
On the server |
What it stops
A stolen laptop, a copied backup, someone reading ~/.ssh on a shared lab machine:
- With a passphrase they hold an encrypted blob. Cracking it is brute force against passphrase quality; a long passphrase makes it impractical.
- Without one they hold your identity to every server that accepted the key, immediately and silently.
On a shared lab account, if everyone can read the key file, every key belongs to everyone. A passphrase forces knowledge of the secret, not access to the file.
# on your laptop — chmod the file private, always
chmod 700 ~/.ssh
chmod 600 ~/.ssh/id_ed25519
File permissions help, but they do not replace a passphrase.
What it does not stop
- A compromised running machine: the unlocked key sits in memory with your session. A passphrase delays nothing.
- A weak passphrase, secret only in the strict sense.
- Anything about the server. It never sees the passphrase, so it cannot be phished over SSH.
Choosing one
The passphrase is typed locally, once per session, not sent over the network. It can be a sentence of words, longer than any password:
# generate a 12-word diceware passphrase with the system entropy, place it in a
# password manager, and type it locally
ssh-keygen -t ed25519 -N "four words you can type fast"
Long beats cryptic. The threat is a brute-forced copy of your file on someone else’s hardware, at millions of guesses per second.
ssh-keygen is interactive by default:
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
-N scripts it, but puts the value in your shell history. Prefer a password manager or
stdin redirection.
ssh-agent
eval "$(ssh-agent -s)" # 1. start a key holder for this shell
ssh-add ~/.ssh/id_ed25519 # 2. unlock the key; prompt appears once
ssh -p 2222 student@127.0.0.1 # 3. and again, and again — no prompts
ssh -p 2222 student@127.0.0.1
ssh -p 2222 student@127.0.0.1
ssh-agent holds unlocked keys in memory for the life of the process. Nothing
plaintext touches disk. You type the passphrase once per agent, not once per
connection.
If the agent dies, run ssh-add again; the disk copy is still encrypted.
To add every key in ~/.ssh: ssh-add -A (macOS), or add each explicitly.
To stop: ssh-agent -k kills the agent and forgets everything.
Your OS can start it at login — systemd user services on Linux, the OpenSSH Authentication Agent on Windows:
Get-Service ssh-agent | Set-Service -StartupType Automatic
Start-Service ssh-agent
ssh-add $HOME\.ssh\id_ed25519
Diagnosing passphrase problems in ssh -v
With a passphrase and no agent holding the key, the failure is client-side and the offer never succeeds:
debug1: Next authentication method: publickey
debug1: Offering public key: /home/you/.ssh/id_ed25519 ...
debug1: send_pubkey_test: no mutual signature algorithm
| Output | Meaning |
|---|---|
Offering public key ... then nothing, then a password prompt |
the key exists but the signature step failed client-side — usually a passphrase you did not enter, or an agent not holding the key |
Could not open a connection to your authentication agent |
ssh-add was used with no agent running |
Bad passphrase, try again from ssh-add |
self-explanatory; type it carefully, the shell hides it |
Permissions ... are too open |
chmod 600 on the private key; on Windows re-check the ACL on .ssh |
Run ssh-add yourself first; its prompt is more direct than ssh’s.
Keys without a passphrase
- A throwaway lab VM you recreate weekly. Set one anyway; it costs one
ssh-agentcommand. - Unattended automation: a CI runner or scripted deployment. The key cannot have a passphrase, so protection moves to scoping, revocation, and keeping it out of a home directory on a laptop.
- A hardware security key or smartcard holds the private key in a device you must
physically touch. The passphrase question disappears; generate one with
ed25519-skinssh-keygen -t.
Key locations, VM use cases, and algorithms
Check yourself — 3 questions
1. A passphrase prompt appears on every connection. Where does that passphrase travel?
Nowhere. It unlocks the key locally; the server never sees it.
2. A laptop with a passphrased key is stolen, powered off. What does the thief have?
An encrypted blob. Cracking it depends on passphrase strength. Without a passphrase, they would have your identity on every server that accepted the key.
3. Which threats survive a passphrase: a compromised running machine, a weak passphrase, or a leak of authorized_keys?
The first two. A running machine has the unlocked key in memory; a weak passphrase is weak. authorized_keys holds only public keys.