SSH Authorized Keys setup – login with no password
SSH Authorized keys allow you to login to a Linux server with no password. This is particularly helpful if you are running an automated script, like a cron job.
For this example, let’s say you want to login in to server B from server A with no password.
a@A:~> ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/a/.ssh/id_rsa):
Created directory ‘/home/a/.ssh’.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/a/.ssh/id_rsa.
Your public key has been saved in /home/a/.ssh/id_rsa.pub.
The key fingerprint is:
3e:4f:05:79:3a:9f:96:7c:3b:ad:e9:58:37:bc:37:e4 a@A
Now use ssh to create a directory ~/.ssh as user a on B. (The directory may already exist, which is fine):
a@A:~> ssh a@B mkdir -p .ssh
a@B’s password:
Finally append a’s new public key to a@B:.ssh/authorized_keys and enter a’s password one last time:
a@A:~> cat .ssh/id_rsa.pub | ssh a@B ‘cat >> .ssh/authorized_keys’
a@B’s password:
From now on you can log into B as a from A as a without password:
a@A:~> ssh a@B
If you would like to login to other remote server C, do not generate a new id_rsa.pub file. Just do the following:
a@A:~> cat .ssh/id_rsa.pub | ssh a@C ‘cat >> .ssh/authorized_keys’
a@C’s password: