creating ssh keys

SSH, or secure shell, is used to access a remote terminal/machine. You can SSH into the CS lab machines from an external computer, or SSH from one lab computer to another.

By default SSH uses your CS password. For many uses (e.g., using Swat GitHub), an ssh key with a passphrase is better or possibly required.

create ssh rsa key

Here’s an example of creating an ssh rsa key:

$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/csmajor1/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): type stuff here...
Enter same passphrase again: type stuff here...
Your identification has been saved in id_rsa.
Your public key has been saved in id_rsa.pub.
The key fingerprint is:
SHA256:wCxmJF7nA76GhKKlp7BAg6wA++/dZ5fp/QMVLekPvpE csmajor1@cheese
The key's randomart image is:
+---[RSA 2048]----+
|      . ..   .  .|
|     . .  . . .o.|
|. . + o    o   ..|
|.o = O .  . .. . |
|o . * O S.   o.  |
| o + o    .  .o  |
|  o   . .o   +.. |
|   . . o.+  +.E. |
|   .o . =.o+..ooo|
+----[SHA256]-----+

using the key

Once you’ve created the key with a passphrase, you’ll generally do something with the public part (here id_rsa.pub). For example, if using Swat GitHub, you’ll upload the id_rsa.pub file.

On the CS machines, if you want to use the key when SSHing from one lab machine to another, add the contents of id_rsa.pub to your ~/.ssh/authorized_keys file, like this:

cd ~/.ssh
cat id_rsa.pub >> authorized_keys

Now try it out: ssh cslab.cs.swarthmore.edu (it should ask for your passphrase instead of your password).

If you made this key on your laptop, and want to use it to access the CS computers, you will need to add the contents of the id_rsa.pub file (on your laptop) to the end of your ~/.ssh/authorized_keys file on the CS computers.

One way to do this is to “cat” out the contents of the pub file (cat ~/.ssh/id_rsa.pub), copy the contents (select with the mouse, then copy), ssh to the CS computers, then edit ~/.ssh/authorized_keys on the CS computers and paste the pub contents at the end of that file.

See also:


Back to SwatCS Help Docs