What are SSH keys
SSH keys are a pair of cryptographic keys that enable secure, password-less remote access to servers and other systems.
Amplifying Workflow with SSH Authentication
SSH authentication serves as a significant enhancer of your research workflow when working with High Performance Computing (HPC) resources. It paves the way for smooth file transfers between your local computer and the server straight from terminal, eradicating the need for repeated password input.
Besides, SSH authentication aid in working on your code locally while executing it remotely, making use of applications like VS Code. A detailed guide to configure VS Code for this purpose can be find in another of my posts.
Do note, for the systems utilizing two-factor authentication, this secondary verification remains mandatory. For instance, Roar Collab server requires full password + second factor authentication once every 24 hours.
Widespread Applicability
While these instructions are primarily tailored for Roar Collab, Penn State’s High Performance Computing (HPC) Cluster, they hold widespread relevance to any server equipped with SSH and SCP capabilities.
Whether you’re working with a different HPC cluster or a standard Linux server, these guidelines can perfectly fit in securing access configuration with an SSH key. Throughout the guide, you’ll encounter placeholders like <psu-id>
and submit.hpc.psu.edu
. Simply replace <psu-id>
with your unique user ID or username, and submit.hpc.psu.edu
with your specific server or HPC cluster’s address.
Step-wise Guide to Use SSH Key
Step 1: Generate SSH Key
- Launch the SSH Agent:
$ alias startssh="eval `ssh-agent -s`"
- Create your SSH key using command:
cd ~/.ssh
ssh-keygen
During the exercise, choose a name for your SSH key. Here, I use <SSHkey_name>
as a placeholder.
Provide an empty passphrase by simply pressing Enter
, and repeat when prompted.
You can verify that this process created two files <SSHkey_name>
and <SSHkey_name>.pub
by running
ls -l
Step 2: Transfer Key to Server
Use this command to copy your SSH key to server:
ssh-copy-id -i ~/.ssh/<SSHkey_name> <psu-id>@submit.hpc.psu.edu
Step 3: Configure Connection
Add these lines to your ~/.ssh/config
file to configure connection:
Host rcollab submit.hpc.psu.edu
HostName submit.hpc.psu.edu
IdentityFile /storage/home/<psu-id>/.ssh/<SSHkey_name>
User <psu-id>
ForwardX11 yes
ForwardX11Trusted yes
Note: You’ll need to create the file, if it doesn’t exist.
This snippet serves two purposes. first, it tells the system where to find your SSH key. Second, using
ssh <psuid>@submit.hpc.psu.edu
to connect to Roar Collab via the terminal, now you can simply do
ssh rcollab
Use this new method to verify that you have set up the SSH key correctly.
Troubleshooting
If the connection fails, start the SSH agent on server:
startssh
Next, add the key:
ssh-add <SSHkey_name>
And that’s about it. Some of your Roar Collab actions can now be automated. Do remember, the password input and two-factor authentication completion is still needed once every 24 hours.
For more detailed insights, these resources can be of help: