You may find it difficult to enter the password each time you try to SSH to the server. This article will help you to log in automatically, without entering the password.
Suppose you want to login to the server Y [hostname or IP] as user y from the local host X where you are user x.
First login on to the local machine X as user x and generate a pair of authentication keys. Do not enter a passphrase:
STEP 1
x@X:~> ssh-keygen -t rsa
Generating public/private rsa key pair. Enter file in which to save the key (/home/x/.ssh/id_rsa): Created directory '/home/x/.ssh'. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/x/.ssh/id_rsa. Your public key has been saved in /home/x/.ssh/id_rsa.pub. The key fingerprint is: 3e:4f:05:79:3a:9f:96:7c:3b:ad:e9:58:37:bc:37:e4 x@X
STEP 2
Now use ssh to create a directory ~/.ssh as user y on Y. (The directory may already exist, which is fine):
x@X:~> ssh y@Y mkdir -p .ssh y@Y's password:
STEP 3
Append x’s new public key to y@Y:.ssh/authorized_keys and enter y’s password one last time:
x@X:~> cat .ssh/id_rsa.pub | ssh y@Y 'cat >> .ssh/authorized_keys' y@Y's password:
Finished !!!
From now on you can log into Y as y from X as x without a password:
x@X:~> ssh y@Y y@Y:~>
Note:
Depending on your version of SSH you might also have to do the following changes:
Put the public key in .ssh/authorized_keys2
Change the permissions of .ssh to 700
Change the permissions of .ssh/authorized_keys2 to 640