Occasionally you need to transfer data between two servers, and you need to have it happen in the background – that is, when you’re not around to type in the password for the user.  In that case, setting up a password-less SSH system in Linux can come in handy.  Especially if you lock down the rights that a user might have; this obviously wouldn’t be the best idea to use root with a password-less SSH system unless there is no other choice and you have firewall settings that help to secure the system.

$> ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/user/.ssh/id_rsa): <strong>[Press ENTER]</strong>
Enter passphrase (empty for no passphrase): <strong>[Press ENTER]</strong>
Enter same passphrase again: <strong>[Press ENTER]</strong>
Your identification has been saved in /home/user/.ssh/id_rsa.
Your public key has been saved in /home/user/.ssh/id_rsa.pub.

You’ll also get some info about the key fingerprint and possibly a “randomart” image, but you won’t need that information.

In the .ssh folder in your home directory you should now have two new files, one call id_rsa and one called id_rsa.pub. The .pub file is the public key that you can share with others.  The id_rsa file is your private key.

To get the public key to the remote server, you’ll want to either log in to the remote server and copy the contents of that file into an “authorized_keys” file in the .ssh folder of your home directory, or just use the ssh-copy-id command:

ssh-copy-id -i ~/.ssh/id_rsa.pub username@remoteserver

This should now enable you to use the shell between the two servers without needing to type in your password.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.