When you create the key pair two files will be generated, a private key e.g. id_ed25519
(or id_rsa
) and the public key id_ed25519.pub
(or id_rsa.pub
). Your private key should never be copied to different machines, however, in order to use your key pair you do need to copy the public key to the remote machine.
Using you normal login password, add the public part of your key pair to the authorized_keys file on the remote host to which you wish to connect. We can use the utility ssh-copy-id
to do this:
ssh-copy-id -i ~/.ssh/id_ed25519.pub [userID]@<hpc-service>
Now you can test that your key pair is working correctly by attempting to connect to the remote host and run a command. You should be asked for your key pair passphase (which you entered when you created the key pair) rather than your remote machine password.
ssh [userID]@<hpc-service> 'date'
Enter passphrase for key '/Home/user/.ssh/id_rsa': [Passphrase]
Wed May 8 10:36:48 BST 2020
We have run date
on the remote server to confirm that we have been able to use the key pair, and passphrase to log in.