User Tools

Site Tools


sshkey

This is an old revision of the document!


Ssh without password

You can connect to the servers using the SSH protocol without the need to insert the password every time you connect. The trick is to generate a encripted key that can be used by the systems to recognize yourself and allow your access to local resources. This behaviour can be used when you are using the Servers from the Epfl Network, but also when you connect to the server from outside the Epfl.

Ssh without password from local workstation

Generate the public/private ssh key pair

Note that this doc applies only to Unix (Mac/Linux). There are similar things on window but they might not work exactly as described here.

  • Login in your workstation and open a Terminal Windows (if you are using the Graphical interface)
  • Execute this command
$ ssh-keygen -t dsa
  • When the system ask a name for the file id_dsa just press enter
  • The system will ask your for a password. This is the password that is used to encrypt your private key file (id_dsa) so that, even if the file gets stolen, it cannot be used. Try to generate a strong password.
  • Now you have to append the content of your public key file ~/.ssh/id_dsa.pub into the ~/.ssh/authorized_keys on the machines where you want to be able to ssh into (e.g. if you are generating the key pair on your laptop, you might want to add the public key on the cluster lth.epfl.ch):
$ cat ~/.ssh/id_dsa.pub | ssh USERNAME@lth.epfl.ch 'cat - >> ~/.ssh/authorized_keys'
  • In our cluster, all the machines have access to the same home directory. Therefore you can use standard local copy:
$ cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys

From now, every time you connet to a server, the server will recognize your workstation automatically (it read the ~/.ssh/authorized_keys file everytime you connect) and you can login without bothering with the password…. well almost! Curious? Continue reading.

Setup ssh-agent

In fact, since your private key is encrypted, you need to type the password that can decrypt it each time you want to use it. Seems like we didn't gain anything till now.

Ssh-agent is a program that keeps in memory your decrypted private ssh key and serves it to ssh when it is needed. In this way you only have to type the decryption password only once. Keeping the decrypted key (or the password) in memory is considered safer than letting the key file un-encrypted.

Let's set it up.

Ssh without password from laptop

Apple Os X & Linux

  • Open a terminal emulation window
  • Execute the command
$ ssh-keygen -t dsa
  • When the system ask a name for the file id_dsa just press enter
  • Do the same for the id_dsa.pub file
  • cd in your .ssh directory with
$ cd ~/.ssh
  • Execute this command
$ cat id_dsa.pub
  • Open another window and from this connect to the public access server lth.epfl.ch. login as usual
  • cd in .ssh directory with
$ cd ~/.ssh
  • Execute the command

$ cat » authorized_keys

  • Now copy & paste with the mouse the key you have in the first window (something that start with sh-dss AAAAB3NzaC1k….) to the second window.
  • press the “Ctrl+d” key combination to close the cat command
  • Try to connect to lth.epfl.ch, this time you can login without inserting the password. If you can't, something is wrong, so you have to recheck all the steps.
sshkey.1302012212.txt.gz · Last modified: 2011/04/05 14:03 by cangiani