Kira Grogg · this is what i do

fb g+ tw pin

SSH login without password

Objective

Quickly login to/from Linux or MacOSX servers using OpenSSH without typing a password each time. That is, automatically login from host1 to host2, either because you are impatient, lazy, or want to call ssh or scp from within a shell script.

Procedure

First log into host1 as user1 and generate a pair of authentication keys. Do not enter a passphrase:

                    user1@host1:~> ssh-keygen -t rsa
                    
                      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:
                      3f:4e:15:79:3a:9f:97:7c:3b:ae:e9:58:37:bc:37:e5 user1@host1
                    

Now create a directory ~/.ssh (or it may already exist) as user2 on host2:

                    user1@host1:~> ssh user2@host2 mkdir -p .ssh
                    user2@host2's password:
                    

Finally append user1's new public key to .ssh/authorized_keys and enter user2's password one last time:

                    user1@host1:~> cat .ssh/id_rsa.pub | ssh user2@host2 'cat >> .ssh/authorized_keys'
                    user2@host2's password:
                    

From now on you can log into host2 as user2 from host1 without a password:

                    user1@host1:~> ssh user2@host2
                    

Note Depending on your version of SSH you might also have to change some file permissions: