ssh-agent(1)
ssh-agent is a program that holds private SSH keys in memory and provides them to SSH clients when needed, eliminating the need to type passphrases repeatedly.
Synopsis
ssh-agent [-c | -s] [-D] [-a bind_address] [-t life] [command [arg ...]]Description
ssh-agent is a background daemon that manages SSH private keys and handles authentication requests from SSH clients. It keeps decrypted private keys in memory so you don't need to re-enter passphrases for every connection. The agent can fork into the background or output shell commands that set environment variables (SSH_AUTH_SOCK and SSH_AGENT_PID) needed for other processes to contact it.
Keys are added to the agent using ssh-add, and remain available until explicitly removed or until the agent exits. This is essential for passwordless SSH authentication in automated scripts and for user convenience when making multiple SSH connections.
Common options
| Flag | What it does |
|---|---|
-s | Output commands suitable for the Bourne shell (sh/bash) |
-c | Output commands suitable for the C shell (csh/tcsh) |
-D | Run in debug mode; do not fork into background |
-a bind_address | Bind to a specific socket address (usually a Unix socket path) |
-t life | Set maximum lifetime for identity keys in seconds |
-k | Kill the current agent (use with pkill as alternative) |
Examples
Start ssh-agent and set required environment variables in the current shell session
eval "$(ssh-agent -s)"Start a new bash shell with ssh-agent running and keys expiring after 1 hour
ssh-agent -t 3600 bashAdd your default SSH private key to the running agent
ssh-add ~/.ssh/id_rsaList all identities currently held by the agent
ssh-add -lTerminate the current ssh-agent and clean up environment variables
eval "$(ssh-agent -k)"Start ssh-agent binding to a custom socket location for this shell session
ssh-agent -a /tmp/my_ssh_socket bash