Setup¶
Before we start the second part of the course and talk about version control, we will need to do a few set up steps. You only need to do these set up steps once for each machine you use Git on.
On CREATE HPC¶
We can use Git to back up our code to a Git host server such as GitHub.com or github.kcl.ac.uk. To communicate with these remote servers we need to set up an SSH key pair. You are already using an SSH key pair to connect from your laptop to CREATE HPC. That SSH key pair lives on your laptop. Here we will create an SSH key pair on the HPC to use to connect from the HPC to the remote server.
Tip
SSH is a cryptographic network protocol that allows secure communication between computers using an otherwise insecure network.
SSH uses what is called a key pair. This is two keys that work together to validate access. One key is publicly known and called the public key, and the other key called the private key is kept private. Very descriptive names.
You can think of the public key as a padlock, and only you have the key (the private key) to open it. You use the public key where you want a secure method of communication, such as your GitHub account. You give this padlock, or public key, to GitHub and say “lock the communications to my account with this so that only computers that have my private key can unlock communications and send git commands as my GitHub account.”
Let's first check if you have already created an SSH key pair on the HPC.
$ ls -al ~/.ssh
If you have already generated an SSH key pair, the public and private keys will be listed. The file names are either id_ed25519/id_ed25519.pub or id_rsa/id_rsa.pub depending on how the key pairs were set up.
If these files don't exist in your home directory, use this command to generate a new key pair, where the -t option specifies which type of algorithm to use and -C attaches a comment to the key (here, your email):
$ ssh-keygen -t ed25519 -C "k1234567@kcl.ac.uk"
If you are using a legacy system that doesn’t support the Ed25519 algorithm, use: $ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
Generating public/private ed25519 key pair.
Enter file in which to save the key (/users/k1234567/.ssh/id_ed25519):
We want to use the default file, so just press Enter.
Created directory '/users/k1234567/.ssh'.
Enter passphrase (empty for no passphrase):
If you are using a machine that others might have access to, it's good practice to create a passphrase for added security. Be sure to use something memorable or save your passphrase somewhere, as there is no “reset my password” option. Note that, when typing a passphrase on a terminal, there won’t be any visual feedback of your typing. This is normal: your passphrase will be recorded even if you see nothing changing on your screen.
Enter same passphrase again:
After entering the same passphrase a second time, we receive the confirmation:
Your identification has been saved in /users/k1234567/.ssh/id_ed25519
Your public key has been saved in /users/k1234567/.ssh/id_ed25519.pub
The key fingerprint is:
SHA256:SMSPIStNyA00KPxuYu94KpZgRAYjgt9g4BA4kFy3g1o k1234567@kcl.ac.uk
The key's randomart image is:
+--[ED25519 256]--+
|^B== o. |
|%*=.*.+ |
|+=.E =.+ |
| .=.+.o.. |
|.... . S |
|.+ o |
|+ = |
|.o.o |
|oo+. |
+----[SHA256]-----+
The “identification” is actually the private key. You should never share it. The public key is appropriately named. The “key fingerprint” is a shorter version of a public key.
Now that we have generated the SSH keys, we will find the SSH files when we check.
ls -al ~/.ssh
On the web¶
Finally, we need to log in to the Git host server we'll use to back up our code, and tell it our SSH public key. First we need to copy the public key. Be sure to include the .pub at the end, otherwise you’re looking at the private key.
cat ~/.ssh/id_ed25519.pub
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDmRA3d51X0uu9wXek559gfn6UFNF69yZjChyBIU2qKI k1234567@kcl.ac.uk
For this workshop we'll use github.kcl.ac.uk as our remote Git host server. Everyone at King's should be able to log in here. It's only accessible if you have a King's account. Alternatively, if you already have an account on GitHub.com, you can use that instead. GitHub.com is more accessible if you're working with collaborators outside of King's, as anyone can create an account.
To add your public key to your github.kcl.ac.uk account (or GitHub.com) account, log in, then click on your profile image in the top right corner, then "Settings". On the settings page, click “SSH and GPG keys”, on the left side “Access” menu. Click the “New SSH key” button on the right side. Now, you can add a title (e.g., "CREATE HPC", so you can remember where the original key pair files are located), paste your SSH key into the field, and click the “Add SSH key” to complete the setup.
Now we can check if the remote Git host server can read our authentication.
ssh -T git@github.kcl.ac.uk
Hi k1234567! You've successfully authenticated, but GitHub does not provide shell access.