Wednesday, July 16, 2008

Automatic SSH login (key based authorization autologin)

The purpose is to be able to connect on an SSH based server without having to enter a password each time. For instance a CVS server using SSH will ask you to enter your password at each command you enter. A passwordless connection would help to work faster!
We consider here that you have a local_user account on your client, and a remote_user account on the server.
Usually, you access your server with the command:
ssh remote_user@remoteserver
Which prompts you for a password.
Steps for having an automatic ssh connection w/o password prompt:
1. Log on the client computer with the local_user account.
2. On the client, create a public key :
ssh-keygen -t rsa
3. Append the generated public key to the remote server:
cat ~/.ssh/id_rsa.pub | ssh -l remote_user remoteserver 'cat >> ~/.ssh/authorized_keys'
4. Access from client to server:
ssh remote_user@remoteserver
5. Correct file access rights if necessary:
In order to work properly, the file ~/.ssh/authorized_keys must be given the access rights to 0600.
ssh remote_user@remoteserver 'chmod 600 ~/.ssh/authorized_keys'  
6. Check that the user is really the owner of his user directories on the server. In particular the home directory!
7. If it does not work, check that the key type is supported. If not, add it to the client. Check also the server side. You can also try ssh -v to see what's not working.
 

You should not be prompted anymore!