# SSH Agent and Passphrases

> Why a private key should have a passphrase. How ssh-agent keeps it open for the day, so you type the passphrase once, not every time.

**Course:** [SSH Keys and Logins](https://learn.benibix.com/learn/infrastructure-ssh)  
**Time:** 10 min

**After this lesson you can:**

- Set a passphrase on a private key
- Load a key into ssh-agent
- Say what a passphrase protects against

## How to lock your key and still log in fast

An SSH key passphrase is a password that locks the private key file itself. If someone copies the file, it is no use to them without the passphrase. ssh-agent is a small program that holds the open key in memory. You type the passphrase once, with ssh-add. The agent then signs each login for you until you log out.

ssh-keygen asks for a passphrase when it makes the key. Leaving it empty is allowed, and many people do. But then the file alone is enough to log in to every server that trusts it.

A laptop can be stolen, and a backup can leak. A passphrase turns either of those into a much smaller problem. A long phrase of four or five plain words is easy to remember and hard to guess.

Typing that phrase forty times a day would be painful. That is the agent's job. ssh-add asks for the passphrase once and hands the open key to the agent. ssh, scp and rsync all ask the agent to sign for them.

The open key lives only in memory, never on disk. When you log out or restart, it is gone, and the next ssh-add asks again. ssh-add -l lists the keys the agent holds right now.

On most desktops the agent starts for you when you log in. macOS can also keep the passphrase in its keychain, so even the first ssh-add happens by itself.

You can add a passphrase to a key you already have. ssh-keygen -p asks for a new passphrase and locks the file with it. The key itself stays the same, so the servers that trust it do not need to change.

```console
$ ssh-add ~/.ssh/id_ed25519
Enter passphrase for /home/lucy/.ssh/id_ed25519:
Identity added: /home/lucy/.ssh/id_ed25519 (lucy@laptop)
$ ssh-add -l
256 SHA256:Xq3v... lucy@laptop (ED25519)
```
Type the passphrase once. The agent now holds the open key and lists it.

![A key file on disk, id_ed25519, is locked by a passphrase. An arrow marked ssh-add, passphrase once, leads to ssh-agent, which holds the open key in memory, never on disk, and loses it when you log out. Three arrows lead from the agent to three logins, ssh web1, ssh shop and rsync to web1, with no passphrase asked. A note says a stolen key file is useless without the passphrase.](https://learn.benibix.com/diagrams/infc-ssh-agent.svg)

### Example: Lucy's laptop is stolen

Lucy's laptop is taken from a cafe. Her private key had a 5-word passphrase, and the laptop was off.

The thief has the key file but cannot use it. That evening, Lucy still deletes its line on her 3 servers. Then she makes a new pair on her new laptop.

**Words in this lesson:** [SSH Key Passphrase](https://learn.benibix.com/term/infrastructure/ssh-key-passphrase), [ssh-agent](https://learn.benibix.com/term/infrastructure/ssh-agent)

**Question:** What does ssh-agent do?

**Answer:** It holds your unlocked key in memory, so you type the passphrase once. ssh-add unlocks the key once and gives it to the agent. The agent then signs each login for you, until you log out.

---

Source: https://learn.benibix.com/learn/infrastructure-ssh/ssh-agent-and-passphrases
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-19
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
