Skills: ssh keys

Use secure keys to avoid being asked for your password when you log in to a remote system.

Until now, every time you log in to Eddie, you are asked for your password. This will quickly become tedious! There is a better way to authenticate yourself: ssh keys. These instructions assume your local computer is running Linux or MacOS. If you are on Windows, look for online instructions.

On your local computer, create a new ssh key pair – when asked for the passphrase, simply hit “Enter” twice.

mkdir -p ~/.ssh
cd ~/.ssh
ssh-keygen -t rsa
 Generating public/private rsa key pair.
 Enter file in which to save the key (/Users/s1234567/.ssh/id_rsa): id_rsa_eddie
 Enter passphrase for "id_rsa_eddie" (empty for no passphrase):

Check your new key pair:

cd ~/.ssh
ls -lrt

where you should find two new files: id_rsa_eddie and id_rsa_eddie.pub. The first one is the private key and needs to be kept secure. The second is your public key, which you can place on a remote computer. Let’s do that now!

On your local computer, display the public key:

cat ~/.ssh/id_rsa_eddie.pub

Log in to an Eddie login node and copy the key there:

ssh s1234567@eddie.ecdf.ed.ac.uk
nano .ssh/authorized_keys

If the file already has some content, don’t change it. Add your public key to the end of the file, save, and exit the nano editor using ctrl-x.

Now we can tell ssh to stop asking for our password and instead to use the key. Modify the entry in your ssh configuration file on your local computer (usually this is ~/.ssh/config)

Host eddie
  HostName eddie.ecdf.ed.ac.uk
  User s1234567
  IdentityFile ~/.ssh/id_rsa_eddie

Now you can log into Eddie without a password:

ssh s1234567@eddie.ecdf.ed.ac.uk

or even better, using the short Host name from your ~/.ssh/config

ssh eddie