May 12, 2007

ssh auto login

Friends,

Last week, I learnt to set up a auto ssh login with remote machines. This will be very useful if you are connecting other machines regularly to linux servers. I thought it will be useful for every if I share it here. Thanks to my colleague Srivatsan who helped me to get it work.

Before you setup auto login, this is how ssh login works. Once you enter the command it will ask for password.

$ ssh -l
XXXXXXXs password:

Let's now see how to set up automatic ssh login with linux machines.


1. first generate a private and public keys using ssh-keygen tool

$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/test/.ssh/id_rsa): sshkeys
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in sshkeys.
Your public key has been saved in sshkeys.pub.
The key fingerprint is:

when it asks to enter passphrase you may just hit enter for empty phrase. That's it you are done with the first step. It will create two files. One is a public key file named sshkeys.pub and another one is private key file named sshkeys

2. Place private key file named sshkeys under /.ssh folder in your machine

3. Now transfer the file sshkeys.pub to the remote machine to which you want to setup auto ssh login. In remote machine append the file /.ssh/authorized_keys with the content of sshkeys.pub file. You may use the following command

cat sshkeys.pub >> /.ssh/authorized_keys

3. Most importantly give following permission only for the files, directories in the remote machine

For /.ssh folder 700 permission (i.e. all permission to users and no permission to group and others)
For /.ssh/authorized_keys file 644 permission (i.e Read,Write for users and Read for group and others)



Now try ssh -l . It should get you to the remote machine with out any questions... Interesting isn't


Hope you like it.

Regards,
Subramanian T