82.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`
    ssh-add ${HOME}/.ssh/id_rsa_github
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 82.10 for details.



Your donation will support ongoing availability and give you access to the PDF version of this book. Desktop Survival Guides include Data Science, GNU/Linux, and MLHub. Books available on Amazon include Data Mining with Rattle and Essentials of Data Science. Popular open source software includes rattle, wajig, and mlhub. Hosted by Togaware, a pioneer of free and open source software since 1984. Copyright © 1995-2022 Graham.Williams@togaware.com Creative Commons Attribution-ShareAlike 4.0