How to set up logging in without a password between your Linux machines

It is very useful to set up passwordless logins between your Linux servers as it can be used for automated tasks, i.e. any cron jobs you may have that requires logging in on another host to run rsync without waiting for you to enter a password.

On the client system that will be logging into a host, create a public/private keypair

We will use ssh-keygen to create a public/private keypair:

$ ssh-keygen

Generating public/private rsa key pair.
Enter file in which to save the key (/home/orfels/.ssh/id_rsa):
Created directory '/home/orfels/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/orfels/.ssh/id_rsa.
Your public key has been saved in /home/orfels/.ssh/id_rsa.pub.
The key fingerprint is:
df:ef:20:c1:89:f2:bb:90:44:f1:c0:d9:cb:7f:8c:2c orfels@vmorfels01

The keys that we created on the client system can now be imported on the remote system to ‘trust’ the client and allowing it to log on without a prompt for the account’s password. When generating the keypair leave the passphrase blank by just hitting return at the prompt.

Copy the public key that we created to the remote system

By using ssh-copy-id we skip the the longer way of doing it, which would involve copying the key to the remote host and then appending the key to authorized_keys on the remote host.

$ ssh-copy-id -i ~/.ssh/id_rsa.pub orfels@remoteserver1
orfels@remoteserver1's password:

Log in from the client to the remote host

Let’s verify that there is no password prompt when starting a SSH session from the client to the remote host:

$ ssh remoteserver1
Last login: Tue Apr 17 17:26:39 2012
orfels@remoteserver1:~$

Be Sociable, Share!

No related posts.