Saturday, February 2, 2013

Password Less SSH

SSH is linux utility to logon to a remote machine for executing command on it.
Every time you ssh to any machine you need to provide username/password to securely login on that machine.

Once a username/password is authenticated, you are logged on that machine and can execute the commands on the remote machine. But to successfully execute a password on remote machine without human intervention, you need to setup SSH such that it don't prompt for password.
E.g.: Hadoop applications requires that Master machine should be able to login to all the slaves machine in cluster password less SSH.

 Linux SSH utility provides a easy way to achieve the password less SSH.
Create  SSH Keys
     ssh-keygen -t rsa  -f ~/.ssh/id_rsa -P ''
       The options are
         -t rsa: Specifies the type of key to create
         -f Specifies the filename of the key file.
         -P Passpharse. Note: we are using empty passphrase.

Copy the public key on the remote machine.
    scp ~/.ssh/id_rsa.pub user@remote.machine:/tmp/id_rsa_.pub_test

Log on to the remote.machine.

Append the content of the file to .ssh/authtozed_keys.
     cat /tmp/id_rsa_.pub_test > ~/.ssh/authorized_keys

Ensure following on the remote machine.
   -  ~/.ssh has permission set to 700
   -  ~/.ssh/authorized_keys has permission set to 640

Alternatively you could use ssh-copy-id command to copy the public key on the remote machine. ssh-copy-id ensures that the correct permissions are set on the remote machine.
  > ssh-copy-id user@remote.machine

Try to SSH on the remote machine, SSH should not ask for the passphase and you should be logged on the remote server.

Reference:
    ssh-keygen linux man page.
    ssh-copy-id linux man page.