So far we have just replaced the need to enter a password to access a remote host with the need to enter a key pair passphrase. Because of this is may be tempting to leave the passphrase empty when creating your key so that we do not have to enter it every time we access a service which may be many times a day. This is poor security practise and is likely to be in breach of the acceptable use policies covering the services you are accessing.
It is also a completely unnecessary risk as you can enable an agent on your local system so that you only have to enter the passphrase once and after that you will be able to access the remote system without entering the passphrase. Here we will demostrate how to use ssh-agent
but:
putty
you can use pageantTo add the private part of your key pair to the SSH Agent, use the ssh-add
command (on your local machine).
ssh-add
By default this will add the files: ~/.ssh/id_rsa
, ~/.ssh/id_dsa
, ~/.ssh/id_ecdsa
, ~/ssh/id_ed25519
and ~/.ssh/identity
, if they exist.
If we want to add a specific key that is not one of these we must specify it explicitly:
ssh-add ~/.ssh/id_ed25519-service
Enter passphrase for home/user/.ssh/id_ed25519_service: [Passphrase]
Identity added: home/user/.ssh/id_ed25519_service (home/user/.ssh/id_ed25519_service)
We can also add keys for a specific length of time. To add the key for one hour we inculde the flag and parameter -t 3600
, you will need to enter your passphrase one more time:
ssh-add -t 3600 ~/.ssh/id_ed25519-service
Enter passphrase for home/user/.ssh/id_ed25519_service: [Passphrase]
Identity added: home/user/.ssh/id_ed25519_service (home/user/.ssh/id_ed25519_service)
Lifetime set to 3600 seconds
Now you can test that you can access the remote host without needing to enter your passphrase:
ssh [userID]@<hpc-service> 'date'
Wed May 8 10:42:56 BST 2020
again we have run date on the remote service to confirm that we have been able to use the ssh-agent successfully.
Remember that in the above user
will be your username on your local machine and that [userID]
is you username on the remote <hpc-service>
.