SSH Keys

From Ryerson Computer Science
Jump to: navigation, search

SSH Keys are a method of method of authenticating trusted computers without the use of passwords. With SSH Keys, you will be able to SSH into servers without having to enter a password in every time.

Generating SSH Keys

OS X or Linux

Generating SSH keys is simple in unix-like operating systems.

In the terminal, execute the following commands

Generate Key

$ ssh-keygen -t rsa
Generating public/private rsa key pair.

Using the above command will generate a 2048 bit rsa key pair.

$ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
Generating public/private rsa key pair.

If you plan on using your keys with Github, or other services, it would be useful to add your email address to your key using the -C flag. The -b 4096 flag above specifies to create a 4096 bit key.

Save Key

Enter file in which to save the key (/home/you/.ssh/id_rsa):

It's recommended to keep your keys in the default location.-

Enter Passphrase

Enter passphrase (empty for no passphrase):
Enter same passphrase again:

It is highly recommended that you enter a passphrase for your SSH keys. In the case where someone gets access to your private SSH key, a passphrase will prevent others from being able to use that key. In OS X, the passphrase can be stored in Keychain, so you will only have to enter it once, Linux also saves the password.

Finishing Up

Your identification has been saved in /home/you/.ssh/id_rsa.
Your public key has been saved in /home/you/.ssh/id_rsa.pub.
The key fingerprint is:
a9:36:01:90:a5:8b:3e:50:ff:18:c0:be:71:a1:f2:28 you@localhost

Windows

RSA Keys can be generating using PuTTYgen.

Using SSH Keys

When generating SSH keys, two files are created, one contains your private key, and the other contains your public key. Your public key is what you use on other servers to authenticate your computer. In the above tutorial, this is the id_rsa.pub file.

Adding SSH Keys to DCS Moon Server

In order to log into the DCS Moon servers without entering your password, you have to add your public key to the ~/.ssh/authorized_keys file. Here are step by step instructions:

$ mkdir ~/.ssh
$ touch ~/.ssh/authorized_keys
$ nano ~/.ssh/authorized_keys

In nano, paste the contents of id_rsa.pub into the file, and then exit and save changes. Log out of the Moon server and log back in to verify your SSH keys were set up properly.