Getting SSH keys to work




Generationg SSH keys


In Linux and macOS SSH keys can be generated in cmd by command:

ssh-keygen -t rsa

In Windows SSH keys can be generated in powershell by command:

ssh-keygen.exe -t rsa

The program prompts the user through the process, just sets the location and asks the user to set a passphrase, which should be created. This process ends with two keys in the path it showed. One of them is named (by default) id_rsa and the other id_rsa.pub. The .pub key is your public key, the other is a private key.

ssh-keygen

NB! Never share your private key with anyone.






Uploading SSH keys to base


Once the keys are created, the public (.pub) key needs to be uploaded to base. There are a couple of ways to do it. On base, SSH public keys are found in /etc/AuthorizedKeys/$USER file, there is a link to it from .ssh/authorized_keys file.

Several SSH keys can be used simultaneously to access the same user account in case of use several different devices.

On Mac and Linux to copy keys to the cluster:

ssh-copy-id Uni-ID@base.hpc.taltech.ee

ssh-keygen

On windows it can be copied in powershell with this command:

type $env:USERPROFILE\.ssh\id_rsa.pub | ssh Uni-Id@base.hpc.taltech.ee "cat >> .ssh/authorized_keys"

A more thorough explanation with an example can be found here.