78.2 SSH Agent

20211005 Entering the passphrase every time you want to do a remote copy or make a remote connection can be tiring. There is a simple mechanism provided to avoid this. by starting up a shell that runs an agent or by informing the current shell to run an agent (ssh-agent) and inform the agent of the passphrase using ssh-add.

An example of starting up a shell with an agent:

ssh-agent bash

Or else simply start the agent within the current shell:

eval $(ssh-agent -s) Then inform the agent of the passphrase just once: $ ssh-add
Need passphrase for .ssh/id_dsa
Enter passphrase for .ssh/id_dsa
Identity added: .ssh/id_dsa (.ssh/id_dsa)

The ssh-add command takes an optional argument to name the file containing the private key.

ssh-add ~/.ssh/id_rsa_github

The -l option of ssh-add lists the key(s) currently kept in memory for this ssh-agent. The -d option removes an identity from memory, named by its file.

When connecting to a remote server over a terminal you can include the following in ~/.profile or ~/.bash_profile to run the agent and prompt for your GitHub key, for example:

if [ -t 0 ] ; then
eval ssh-agent -s
fi
The -t for the test command ([) tests if the file descriptor 0 (stdin) is open on a terminal, which it will be for an interactive terminal.
Note that r_linux_command("ssh-agent") is usually run automatically for a remote desktop X11 connection, and so only ssh-add will be required. See Section 78.10 for details.