This episode is drawn from a number of resources:
We may be tempted to think that our work isn’t valuable enough to be hacked so we don’t need to take cybersecurity seriously. However, what we must understand is that HPC resources as well as many services you will use, are shared resources. They are used by many researchers studying a wide range of problems and are only as secure at the weakest link in the chain.
Any issues arising from the actions of one individual can therefore impact many of your colleagues and result in resources being taken offline whilst issues are investigated and remedied. Furthermore HPC systems are expensive resources typically run by small or modest sized teams so impacts, whilst hopefully rare, can be costly in time and personpower. This is before we consider the potential loss of data or breaches of sensitive data.
As HPC services are remote machines, interaction is done over an encrypted communication channel called Secure Shell version 2 (SSH-2). This allows command-line access to one of the login nodes of a HPC service, from which you can run commands or use a command-line text editor to edit files. ssh
can also be used to run graphical programs such as GUI text editors and debuggers when used in conjunction with an X server.
Linux distributions and macOS each come with an installed terminal application that can be used that can be use for SSH access to the login nodes. Linux users will have different terminals depending on their distribution and window manager (e.g. GNOME Terminal in GNOME, Konsole in KDE). Consult your Linux distribution’s documentation for details on how to load a terminal.
macOS users can use the Terminal application, located in the Utilities folder within the Applications folder.
You can use the following command from the terminal window to login into an HPC service:
ssh [userID]@<hpc-service>
To allow remote programs, especially graphical applications to control your local display, such as being able to open up a new GUI window (such as for a debugger), use:
ssh -X [userID]@<hpc-service>
Some sites recommend using the -Y flag. While this can fix some compatibility issues, the -X flag is more secure.
Current macOS systems do not have an X window system installed by default. Users should install the XQuartz package to allow for SSH with X11 forwarding on macOS systems:
A typical Windows installation will not include a terminal client, though there are various clients available. We recommend all our Windows users to download and install MobaXterm to access HPC facilities. It is very easy to use and includes an integrated X server with SSH client to run any graphical applications.
You can download MobaXterm Home Edition (Installer Edition) from the following link:
Double-click the downloaded Microsoft Installer file (.msi), and the Windows wizard will automatically guides you through the installation process. Note, you might need to have administrator rights to install on some Windows OS. Also make sure to check whether Windows Firewall hasn’t blocked any features of this program after installation.
Start MobaXterm using, for example, the icon added to the Start menu during the installation process.
If you would like to run any small remote GUI applications, then make sure to use -X option along with the ssh command (see above) to enable X11 forwarding, which allows you to run graphical clients on your local X server.
A common option found on many University systems is to use Putty/Kitty
If you are using Windows Subsytem for Linux then you can install ssh
as described above in Logging in from Linux and macOS.
To log into your HPC service you should replace the [userID] and
ssh [userID]@<hpc-service>
On local, HPC systems you may be able to use your standard institutional credentials. On other services you will typically be provided with your initial password for logging onto the system.
When you log into a new service for the first time you will likely be asked to change your password. If you are not, you should change it at first log-in with the command passwd
. Once you have logged in or run the command, the password change sequence is:
There may be a forced password policy to help ensure that you are using a strong password.
N.B. You may be logged out and can now log back in with your new password.
You may now change your password on the machine itself using the passwd
command. If you forget your password, you should contact your system administrator/helpdesk.
Some systems will also/instead require you to set up an SSH key pair to access the services. The SSH key pair consists of a private part and a public part. The public key can be put on remote machines to allow you to log-in without the use of a password. You keep the private part of the key secure on your local machine protected with a passphrase.
Public key encryption uses fancy maths to enable secure communication over an open channel. There are a number of methods the most common being RSA) which uses prime numbers. If you are going to use this you should use a key size of at least 2048 and preferably 4096. Public keys can be broken with brute force computation and the longer the key the more secure it is.
An alternative encryption method and the one we recommend you to use are based on EdDSA (Ed25519). For our purposes the key pair works in the same way. Your public key can go on the remote resource or service and the private key is kept protected on your local machine. You can generate a key pair with:
ssh-keygen -o -a 100 -t ed25519
ssh-keygen
is the command to generate the key pair-o
specifies to use a strong format to save the key-a 100
increases the strength of encryption with your passphrase-t ed25519
specifies the encryption method usedWhen you create a SSH key pair you will be prompted to provide a passphrase
. This is effectively password for your private key and like a password should be kept secret. Now when you try to use the key, you should be asked for your key pair passphase (which you entered when you created the key pair) rather than your remote machine password.
If you have a Windows machine then you can create keys with:
They use essentially the same interface to generate keys with these instructions.
On systems running older version of ssh you may not be able to use the EdDSA
encryption. In this case you should use:
ssh-keygen -o -a 100 -t rsa -b 4096
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.
So far we have generated a single key with a default name for one service. Using strong keys means that the key should secure but what happens if the key is compromised? An intruder can now access all systems on which we use this key. Therefore it is good practice to use a different key for each service you use. In order to do this you need to specify the name of key file:
ssh-keygen -o -a 100 -t ed25519 -f ~/.ssh/id_ed25519_service
Before when we connected to the remote machine ssh
automatically tried default keys it found in ~/.ssh
. We can specify that we wish to use a specific key with:
ssh -i ~/.ssh/id_ed25519_service [userID]@<hpc-service>
However we now have an issue that we need to remember and specify the key we want to use for each service and typeout a longer command each time we want to connect to remote machines. We can simplify this by adding the Host, and key file to our ssh config. Edit ~/.ssh/config
and add/include:
Host <hpc-service>
IdentityFile ~/.ssh/id_ed25519_service
Now when we connect to the service:
ssh [userID]@<hpc-service>
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>
.
We are now able to connect securely and conveniently to remote systems. But what happens if we want to move data between remote systems. We can use agent forwarding to enable the use of keys stored in our local agent on the remote systems. This allows us use our private keys for onward connections without having to store a copy of the private key on the shared system.
First we must modify our ~/.ssh/config
to turn on agent forwarding for each host where we want to enable it. e.g. we would do include this for a remote service that where we wanted to push to another sytem or e.g. github, but would not use include it for github:
Host serviceA
HostName <hpc-service>
IdentityFile id_ed25519_service
User userid_service
ForwardAgent yes
We have also added HostName
, which will be the full name of the server we connect to, so we can now connect to ssh [userID]@<hpc-service>
with just ssh serviceA
.
Now we need add the key for serviceA to our agent:
ssh-add -t 3600 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
and the key for the onward service we wish to connect to:
ssh-add -t 3600 id_ed25519_github
Enter passphrase for home/user/.ssh/id_ed25519_github: [Passphrase]
Identity added: home/user/.ssh/id_ed25519_github (home/user/.ssh/id_ed25519_github)
Lifetime set to 3600 seconds
Now we can connect to the service and use our github key on the remote machine. Note that both keys will be forwarded by the agent.