Getting to grips with SSH – Part 1

By Ollie Armstrong Wednesday, 2nd June 2010

SSH-guides

Welcome to the first of a series of blogs taking you through the basics of using ssh commands, not only to access your CatN vCluster, but for general network administration.

If you’re not sure what ssh is, or you want to jump to vCluster specific instructions for ssh have a look here: What is a shell environment?, here: SSH access for your vCluster, and here: SSH key pairs.


Getting Started

This first tutorial will take you through the steps of setting up a Windows machine with an ssh client, and generating an ssh key pair on both Windows and Mac OSX (you Linux users know how to do this already right?).


Windows

Windows does not natively support ssh. This means you need to install a program that is an ssh client, that you can use to gain ssh access to a network location.

The most popular ssh client for Windows is a program called PuTTY that you can download from here. On the PuTTY download page make sure you download the Windows installer, as this package includes PuTTYgen, a vital program for generating your ssh key pair.ssh commands

Run the file once it’s finished downloading and install the program.

Look in your start menu and run “PuTTYgen”. This will generate your public and private ssh keys that you can then add to the CatN control panel.

Select the “Generate” option in the actions menu, and follow the instruction to move your mouse over the empty space. These random movements will generate a unique key.

When complete save both the Public and Private keys. Select “Save public key”, and choose a location on your computer to save this file. You may find it useful to create a PuTTY folder in your My Documents. Now select “Save private key”, and again, choose a location to save this file on your computer.

Select “Save public key”, and choose a location on your computer to save this file. You may find it useful to create a PuTTY folder in your My Documents. Now select “Save private key”, and again, choose a location to save this file on your computer.

Now you can double click the private key logo to start the PuTTY terminal and set the server to ssh to. We’ll cover that in Part 2!



SSH is supported natively on the Mac OSX, so there is no need to download an ssh client like PuTTY. Instead we can skip straight to the ssh key pair generation.

Unlike PuTTY in windows that uses a user interface, a key pair is generated in Mac OSX using a terminal. So the first thing you need to do is fire that terminal up! Click “spotlight” and start typing “Terminal” and you’ll find it quick enough.

In the terminal we need to change to the ssh key directory to check if a key is already there. Type:

$ cd ~/.ssh

If you get a “No file or directory” error than you can skip the next step…>

If a key pair does exist follow these next steps:

Enter these commands:

$ ls
id_dsa		id_dsa.pub	id_rsa		id_rsa.pub	known_hosts
$ mkdir key_backup
$ cp id_rsa* key_backup
$ rm id_rsa*

This process copies the current ssh keys into a backup directory, and clears the directory for generating your new keys.

Go back to your terminal and type:

$ ssh-keygen -t dsa

Generating public/private dsa key pair.
Enter file in which to save the key (/Users/joegardiner/.ssh/id_dsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /Users/joegardiner/.ssh/id_dsa.
Your public key has been saved in /Users/joegardiner/.ssh/id_dsa.pub.
The key fingerprint is:
a7:e2:81:76:46:9a:48:cb:67:0d:34:6b:b2:78:81:6a joegardiner@Joe-Gardiners-iMac.local
The key's randomart image is:
+--[ DSA 1024]----+
|                 |
|                 |
|    o            |
| . . o           |
|. + + . S .      |
|.+ B B   o       |
|oE* B * .        |
|.. + + o         |
|      .          |
+-----------------+

When prompted for the save location, you can just press Enter to choose the default. You should use a passphrase when working with your keys for security measure. Have a look at this guide for more information about working with passphrases.

Now we can view the public key with one simple command:

$ cat .ssh/id_dsa.pub

This commands concatenates the key we have just generated and displays it as text. Here is the output from that command when I execute it.


ssh-dss AAAAB3NzaC1kc3MAAACBANT0vFIneyaW0Dbyk0quf3nr0P1AC8KMuE9KUvAM4bPhS/O4dlxFaQtxbfc8
/KDvkvEmqRVIMZPtyRN1LpDbrIT+k0cc3pi++A/6wFhegJsSmBzvfN8y49jBePEzG0z+ob1mDg0sbdhiI
yZzAS5N0otBViNGuPlc7T25+EuXqFV7AAAAFQCX33ZKB64MKL3xXyULAKC2jvc30wAAAIAMP6DKpoP5Vr8iey
WoAIbBQ1ijcXP/zeyQS8qHqAvCZoWXgWRTHiA2jGgjFgkRtFNrUhUUk+8nEb2/37U0MZ+c9eRDUPOAXMRlWjfwsLLb71XD
Ct8czstLpoAuOsfOf2yt++cFY7nEIFR/TS7Xhf2Oz4mCk3Ni/Pd8wdFpAUToWAAAAIALAGZ9iYAVZTX
ttcSKJO7XGNsxS9wxAxAE9ftAi2DAekuDjIMZcRcA9I3yc0VApjdfFMjPIICLHXXV+ThmFfXVoD0baOKI7p
Kd8LVE3SHZ6srs1sGfHl65A5DwY/zvLoZLxp8Ks08Ufu/xQupeQQ1nhclSJCO49vBHtPW8uJdXOA==
joegardiner@Joe-Gardiners-iMac.local

The keys will be stored in the .ssh directory, so there is no need to issue a save command in the terminal.


Conclusion

Now that we can generate a key in Windows and Mac OSX, in the next guide we will look at using the key pair and a terminal to gain access to a server using ssh commands.


Posted in Guides, SSH | No Comments » twitter-follow facebook-follow rss-follow

Leave a Reply

Your email address will not be published. Required fields are marked *