Tuesday, August 31, 2010

Login To A Linux Server Without Password

Lets suppose that you need to run a command to update a module on multiple servers via ssh. Though using parallel ssh to save time, you would require to provide passwords on each server each time you will login. So the ultimate problem still remains their. Hows that if it would be possible that you run the command through parallel ssh and the operation went on smoothly without asking for any password..

Here how it would be-

1. Generate a pair of authentication keys. Give the command as below-

Note: even if is unsecured to work without password, do not enter it. Let it empty...


ssh-keygen -t rsa
You will get the output as below-
Generating public/private rsa key pair.
Enter file in which to save the key (/home/user1/.ssh/id_rsa):
Created directory '/home/user1/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/user1/.ssh/id_rsa.
Your public key has been saved in /home/user1/.ssh/id_rsa.pub.
The key fingerprint is:
31:df:a5:73:4a:2f:a6:6c:1c:32:a2:f2:b3:c5:a7:1f user1@computer1

The above command will generate id_rsa.pub key file in your /home/user1/.ssh folder

2. Now you need to copy this file to the ssh folder in the target server. Follow the command below-

cat .ssh/id_rsa.pub |ssh -p 99 root@72.52.93.20 'cat >> .ssh/authorized_keys'

where -

* -p is used to define port number of ssh.
* 99 is the port number.
* id_rsa.pub is the key file.
* root is the username to login with.
* 72.52.93.20 is the IP of the target server.
* .ssh/ is the ssh folder under root directory.
* authorized_keys is the id_rsa.pub file copied as authorized_keys on target server.

The CAT command will copy the id_rsa.pub file as authorized_keys file on the target server. You will be asked for the password while copy. 

If you wish you can restrict this file to be accessed by you only by setting the permission.

chmod 644 *

Now  you can try login to the server by typing its IP or name at your terminal and it should logged-in directly without asking for any password.

1 comment:

  1. How to login without password on linux its really helpful to me. I get it clear idea about your topic.All the points are explained very clearly.web hosting

    ReplyDelete