SSH Login Without Password

  |   Source

If you want to ssh from 'userx' of host X to 'usery' of host Y without typing password, you need to do the following.

  1. Log in on host X as userx and generate a pair of authentication keys. Make sure not to enter a passphrase:
    userx@X:~> ssh-keygen -t rsa
    Generating public/private rsa key pair.
    Enter file in which to save the key (/home/userx/.ssh/id_rsa): 
    Created directory '/home/userx/.ssh'.
    Enter passphrase (empty for no passphrase): 
    Enter same passphrase again: 
    Your identification has been saved in /home/userx/.ssh/id_rsa.
    Your public key has been saved in /home/userx/.ssh/
    The key fingerprint is:
    3x:5f:05:79:3d:8f:9e:7c:3b:ad:e9:58:37:bc:37:e4 userx@X
  2. Log in on host Y as usery and then create a directory ~/.ssh on Y. (It's okey if the directory already exist):

    userx@X:~> ssh usery@Y mkdir -p .ssh
    usery@Y's password:
  3. Append X's new public key to usery@Y:.ssh/authorized_keys and enter usery's password one last time:

    userx@X:~> cat .ssh/ | ssh usery@Y 'cat >> .ssh/authorized_keys'
     usery@Y's password:
  4. That's it! Now on you can log into Y as usery from X as userx without password.

    user@X:~> ssh user@Y

Depending on your SSH version you might also have to do one of the following changes:

  • Change the permissions of .ssh to 700 and anything inside to 600

    userx@X:~> chmod 700 ~/.ssh && chmod 600 ~/.ssh/*
      userx@X:~> ssh usery@Y chmod 700 ~/.ssh && chmod 600 ~/.ssh/*
  • Put the public key in .ssh/authorized_keys2 and the change the permissions of .ssh/authorized_keys2 to 640