$linuxjunkies
>

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.

UbuntuDebianFedoraArch

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

FlagWhat it does
-sOutput commands suitable for the Bourne shell (sh/bash)
-cOutput commands suitable for the C shell (csh/tcsh)
-DRun in debug mode; do not fork into background
-a bind_addressBind to a specific socket address (usually a Unix socket path)
-t lifeSet maximum lifetime for identity keys in seconds
-kKill 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 bash

Add your default SSH private key to the running agent

ssh-add ~/.ssh/id_rsa

List all identities currently held by the agent

ssh-add -l

Terminate 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

Related commands