Friday, November 13, 2009

SSH without Password Authentication

I feel very difficult to type passwords always when i login to our institution's remote server Athena. Recently i found this tip helped me a lot. I am sure it will help you.
Here we are using some cryptographic approach of generating a public key and private key pair.Don't think it's difficult ..i am not going to teach u about cryptography..


So follow these steps:[ with each command i will giv u a little explanation. You should know what you are doing ] .I assume that you have got ssh installed in your system(it will be there by default in many distros) and you have an account in remote server.

1) ssh-keygen -t dsa

Here you are generating key pair.The program will ask a series of prompted questions. For our purposes, it is Ok to just keep pressing the "enter key" for the defaults.

2) ls -l ~/.ssh

It will show like this. The file id_dsa.pub is the public key file.
total 12
-rw------- 1 irfan irfan 736 2009-11-12 23:45 id_dsa
-rw-r--r-- 1 irfan irfan 604 2009-11-12 23:45 id_dsa.pub
-rw-r--r-- 1 irfan irfan 2210 2009-11-12 18:43 known_hosts


3) chmod 700 ~/.ssh
chmod 600 ~/.ssh/*


This will make sure the user have necessary permissions with the file.( i will explain chmod in my coming posts..)

4) Copy the id_dsa.pub file to ~/.ssh folder of your account in remote server.I do it as:

scp id_dsa.pub username@server_address:~/.ssh

[Don't forget the colon : ]

5) Now login to your remote server

ssh username@remote_address

6) append contents of file id_dsa.pub to the file named authorized_keys2 . follow this command:

cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys2

[ do this even if the file named authorized_keys2 is not found in .ssh folder ]

7) Ensure the permissions once more

chmod 700 ~/.ssh chmod 600 ~/.ssh/*

DONE..

Next time onwards when you login to the server it wont ask you the password.

//Feel free to ask any clarifications