Menu

Tuesday, July 19, 2011

SSH without password

This tutorial explains on how to SSH to the server without providing password. This will helpful when there is necessary to do automation process or to keep on logging to the server regularly.

Step 1. Generate the authentication keys in the client system. These keys can be generated using the RSA or DSA algorithm. RSA algorithm is much faster than DSA where as the DSA is more secure.
    
     # ssh-keygen -t rsa

     By default, the key generated by the above command will be in /root/.ssh/id_rsa if you login with root directory. When you generate the key, don’t enter password.

     
     The above command will generate one private and one public key as shown in the below picture.



Step 2.  In the server system, create .ssh directory if it doesn’t exists and then create an authorized_keys file.

# ssh username@server
# mkdir –p .ssh
# touch authorized_keys
# exit

Step 3.  Now append the public key (id_rsa.pub) which is created on the client system in the authorized_keys. and change mode of the .ssh directory and authorized_keys file.

# scp /root/.ssh/id_rsa.pub user@server:/tmp
(copy the id_rsa.pub key to temp directory in the server)
# cat /tmp/id_rsa.pub >> /.ssh/authorized_keys

# chmod 700 .ssh
# chmod 600 .ssh/authorized_keys

Step 4.  Once you complete everything, log into the server from client system. It will not prompt for password.

# ssh user@server