ssh-agent program is a daemon (a process that runs in the background) which stores your passphrases in memory, allowing you to easily access remote servers without typing a passphrase each time.
For our case, we have already created SSH keypairs with
ssh-keygen and used
ssh-copy-id to upload our private keys onto the authorized_keys file on our server. The only problem now is that we must input our passphrase upon every connection. Let's see how
ssh-agent can help automate this task.
To start the
ssh-agent, input the command followed by
$ ssh-agent bash
This will spawn a new bash process, in which
ssh-agent runs in the background and stores the keys in memory. Now we can add our actual keys with
Enter passphrase for /home/user/.ssh/id_rsa: Identity added: /home/user/.ssh/id_rsa (/home/user/.ssh/id_rsa)
If your key is not in the canonical ~/.ssh directory, or has a different filename, type its path directly after the
ssh-add command (e.g.
Congratulations! Now your passphrase has been added to the
ssh-agent, and you will no longer need to input the passphrase. Now try logging into your server.
$ ssh firstname.lastname@example.org
Last login: Mon Dec 21 05:19:49 2015 from 220.127.116.11 [email@example.com ~]$
Remember that once you exit out of the bash terminal spawned with
ssh-agent, your passphrases will be lost and you'll have to run
Sometimes you'll need to check whether the
ssh-agent is running or not. We can do so by checking our processes.
$ ps aux | grep ssh-agent user 2411 0.0 0.0 10616 524 ? Ss 05:35 0:00 ssh-agent bash
To view the keys that have been successfully added to the ssh-agent, use the
$ ssh-add -l 2048 ec:39:69:3d:c4:8b:63:fd:57:a3:78:51:6d:cd:cd:46 /home/user/.ssh/id_rsa (RSA)
Stretch out your back and relieve your back muscles with inversion therapy. This device counteracts the forces of gravity on the body by decompressing and elongating the spine. By using this product just ten minutes a day, you can be well on your way to improved circulation and posture while relieving muscle aches, back pain and stress.$$ Check price
The Linux Command Line takes you from your very first terminal keystrokes to writing full programs in Bash, the most popular Linux shell. Along the way you'll learn the timeless skills handed down by generations of gray-bearded, mouse-shunning gurus: file navigation, environment configuration, command chaining, pattern matching with regular expressions, and more.$ Check price