Providing your ssh key

From ScotGrid

Table of contents

Mac OS X

Step 1

Check to see if you already have a public/private key pair for your user. If you do, it will be in your ~/.ssh directory.

[~]$ cd .ssh
[~/.ssh]$ ls
config                id_rsa.pub
id_rsa                known_hosts

Key pairs are always named like something and something.pub. The something file is your private key and must be kept secret. The something.pub file is your public key, and this is what you’ll be giving us. If you already have a key pair (in the above listing I have an id_rsa key pair) and you want to use it for ScotGrid, then skip to Step 3.

Step 2

If you don’t have any keys yet, then you’ll need to generate them. This can be done with the ssh-keygen program.

[~/.ssh]$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/dug/.ssh/id_rsa): <enter>
Enter passphrase (empty for no passphrase): <enter passphrase or hit enter>
Enter same passphrase again: <enter passphrase again>
Your identification has been saved in /Users/dug/.ssh/id_rsa.
Your public key has been saved in /Users/dug/.ssh/id_rsa.pub.
The key fingerprint is:
50:43:77:c6:97:af:61:82:dc:ea:9b:6b:67:d4:1b:61 dug@scotgrid

The passphrase that you enter will be requested from you every time you use the key. You can use ssh-agent (http://www.phil.uu.nl/~xges/ssh) or the built-in keychain support to automate password entry, or you can simply hit enter to not use a passphrase.

Step 3

Copy your public key to the clipboard so you can easily paste it into an email.

[~/.ssh]$ cat id_rsa.pub | pbcopy

The pbcopy command copies whatever is sent to it via STDOUT to the clipboard, ensuring that you won’t have any extraneous newlines or other problems.

Linux

Step 1

Check to see if you already have a public/private key pair for your user. If you do, it will be in your ~/.ssh directory.

[~]$ cd .ssh
[~/.ssh]$ ls
config                id_rsa.pub
id_rsa                known_hosts

Key pairs are always named like something and something.pub. The something file is your private key and must be kept secret. The something.pub file is your public key, and this is what you’ll be giving us. If you already have a key pair (in the above listing I have an id_rsa key pair) and you want to use it for ScotGrid, then skip to Step 3.

Step 2

Generate a public/private dsa key pair if you don’t already have one. This is done with the ssh-keygen.

[~/.ssh]$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/dug/.ssh/id_rsa): <enter>
Enter passphrase (empty for no passphrase): <enter passphrase or hit enter>
Enter same passphrase again: <enter passphrase again>
Your identification has been saved in /home/dug/.ssh/id_rsa.
Your public key has been saved in /home/dug/.ssh/id_rsa.pub.
The key fingerprint is: <hex string>

The passphrase that you enter will be requested from you every time you ssh. You can use ssh-agent to automate password entry, or you can simply hit enter to not use a passphrase.

Step 3

Email your public key to ScotGrid.

Copy your public key to the clipboard so you can easily paste it into your web browser. If you have xclip installed then:

[~/.ssh]$ cat id_rsa.pub | xclip

The xclip command copies whatever is sent to it via STDIN to the clipboard (you may have to use xclip -selection clipboard), ensuring that you won’t have any extraneous newlines or other problems. Now you can simply paste in your public key into an email! If you don’t have xclip then either install it using your OS’s package manager or print out the public key to a terminal so that you can manually copy the key data.

[~/.ssh]$ cat id_rsa.pub
ssh-rsa tHisIsUttErRubBisHSoDoNtEvEnTryToCopYCrAcKoRuSEiTinAnyWay/hLDjENHThzP5ku
PDsitSSUH2MATP014G/3BzaI9pdnhf02MSEcmtmIKXrm05/dzxEmp9yOY32YHyk6/rLUGGTJuWOpGt3J
6H5LWxq9yeRUuFG/pCRH3+KxOyzasSHXfXJaC5v7wPxUdAeg9k0jwsUjnqUcYvzo5+GwCXV9dIwY3Sr/
OrL2l8SCdSWyd3PLufJXKQHlouHB0NI/+G/QjWmkB8c1PJh/VuIe36mqv82V9XXKvYNaVWwz5Sg6aY9u
p2lgDEme+AFdPPjOnkdF6OHCr7ymKg6c/B2YCbOW7QN/L4uAdVOhTNnJMQ== dug@scotgrid

Copy the entirety of the public key to the clipboard. It is important that there are no newlines in the key (copying from the cat output in your console should work properly.

Windows(Putty)

If you don’t have any keys yet, then you’ll need to generate them. This can be done with the PuTTYgen tool, provided by the PuTTY project (http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html). There is also an installer available that includes all of the PuTTY tools.

  • Start PuTTYgen
  • Select SSH2 RSA or SSH2 DSA and press the “Generate” button.
  • PuTTYgen will prompt you to “generate some randomness by moving the mouse over the blank area”. Once this is done, a new public key will be displayed at the top of the window.
  • Enter a comment if you like, this will be used as the key’s “name”.
  • Enter a passphrase if you wish. Note that you will be asked for this passphrase every time you ssh. We only recommend using a passphrase if you are concerned other users may gain access to your keypair files.
  • Save the public and private keys somewhere. We recommend the openssh default: `/.ssh/id_rsa.pub` and `id_rsa` (or `id_dsa.pub` and `id_dsa` for a DSA pair)
  • Copy the public key and paste it into an email.

You may wish to set up Pageant (http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html) to manage your keys.

Problems?

I am not able to ssh into gla057@svr020.gla.scotgrid.ac.uk .. it says permission denied please try again.

In case you have named your private key differently try creating a config file in the .ssh directory containing the following to point to the relevant IdentityFile. In this case id_rsa.

[~/.ssh]$ cat config
Host svr020 scotgrid
  User gla057
  Port 22
  Hostname svr020.gla.scotgrid.ac.uk
  IdentityFile ~/.ssh/id_rsa
  GSSAPIDelegateCredentials no
  ForwardX11 yes