If SSH asks for your private-key passphrase every time you connect, ssh-agent can save you the repeat prompts. It holds an unlocked key identity in memory and signs authentication requests for your SSH client. Your private key is not sent to the remote server.
The agent is optional: OpenSSH can use a key file directly. An agent is useful when you want to unlock a passphrase-protected key once and reuse it for SSH, Git, or SFTP connections.
Check before starting another agent
On Linux and macOS, a desktop session may already have started an agent. Check whether your current shell can reach one:
ssh-add -l
There are two common outcomes:
- “The agent has no identities.” The agent is reachable, but no keys are loaded.
- “Could not open a connection to your authentication agent.” Your shell cannot reach an agent.
If the agent is reachable but empty, add your private key (substitute its actual filename if needed):
ssh-add ~/.ssh/id_ed25519
ssh-add -l
Use the private-key file, not its .pub counterpart. The final command should list the loaded key’s fingerprint and type.
If no agent is reachable in a Linux or macOS shell, start one for that shell and load the key:
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
ssh-agent -s prints shell statements containing the agent’s socket details. eval applies them in the current shell, so commands there can find the agent. Don’t add this startup command unconditionally to every shell: you may create redundant agents when your login session already provides one.
Windows uses a service
Windows OpenSSH uses the OpenSSH Authentication Agent service, rather than the per-shell eval setup. Configure it from PowerShell running as Administrator:
Get-Service ssh-agent
Set-Service -Name ssh-agent -StartupType Automatic
Start-Service ssh-agent
Then use a regular PowerShell window to load and check your key:
ssh-add $env:USERPROFILE\.ssh\id_ed25519
ssh-add -l
On a managed computer, organization policy may control the service settings. If Git still prompts for the passphrase, check which SSH executable it uses with where.exe ssh. Git for Windows may use a different SSH binary from Windows OpenSSH, so its agent connection may not be the one you configured.
Useful ssh-add commands
ssh-agent runs the agent; ssh-add manages the identities it holds. These commands cover common day-to-day tasks:
ssh-add -l # List fingerprints; check agent access
ssh-add -L # Print loaded public keys
ssh-add -t 1h ~/.ssh/id_ed25519 # Load a key for one hour
ssh-add -d ~/.ssh/id_ed25519 # Remove one identity
ssh-add -D # Remove all identities
Removing an identity from the agent does not delete the key file. Likewise, ssh-add -L prints public keys, not private keys. If you share command output or screenshots, consider whether the fingerprints or public keys identify your environment.
If SSH keeps prompting, verify that the agent has the same key your connection uses. An explicit IdentityFile setting can help select a particular key; the SSH IdentityFile guide covers selecting and checking keys in OpenSSH configuration.
Treat agent forwarding as access, not a convenience switch
Agent forwarding lets a remote machine ask your local agent to sign authentication requests while the SSH connection is active. It does not copy your private key to that machine. But a process on a remote host with access to the forwarded socket may still use the agent’s signing capability. That’s why a forwarded agent can be abused even when the key itself never leaves your computer.
Keep forwarding off unless a specific task requires it. ssh -A user@host enables forwarding for a connection; ssh -a user@host disables it. The lowercase -a controls forwarding only—it does not stop your local client from using keys to authenticate to the first host.
If you need to reach an internal server through a bastion, consider ProxyJump (ssh -J) rather than forwarding your agent to the bastion. The SSH jump-host guide explains that connection pattern.
When the socket is missing or stale
On Linux and macOS, SSH_AUTH_SOCK tells clients where to contact the agent. Inspect it alongside the agent check:
printf 'socket: %s\n' "$SSH_AUTH_SOCK"
test -n "$SSH_AUTH_SOCK" && test -S "$SSH_AUTH_SOCK" && echo 'socket exists'
ssh-add -l
An empty variable means the current shell doesn’t know the socket. A socket path that exists doesn’t guarantee the agent is usable, so check ssh-add -l too. This can happen after reconnecting to SSH or reattaching to tmux: an existing shell may retain an old socket value. Confirm the current session’s socket instead of copying an old path blindly.
The practical rule is simple: check for an agent first, load only the key you need, and forward the agent only when the remote task requires it.
I originally published a more detailed version of this guide on the ShadeTerm blog.
I'm also building ShadeTerm — an SSH client where every server gets its own workspace for terminals, SFTP, code, and databases.
Top comments (0)