In this short article, I’m going to show you how to setup SSH Public/Private keys to allow you to SSH into a Linux server without needing to enter your password each time. This is not only a great convenience, but becomes useful for any scripting that utilizes SSH to transfer files from one server to another in an automated way.
On the local computer, enter the following command:
ssh-keygen -t dsa
You should see something similar to the following:
Generating public/private dsa key pair. Enter file in which to save the key (~/.ssh/id_dsa): (hit return)
Enter passphrase (empty for no passphrase):(hit return)
Enter same passphrase again:(hit return)
Your identification has been saved in ~/.ssh/id_dsa Your public key has been saved in ~/.ssh/id_dsa.pub The key fingerprint is: (A long string of random characters will be displayed.)
This generates a folder and several files. Paste the content of
~/.ssh/id_dsa.pub into the file
~/.ssh/authorized_keys on the remote host. There are two ways to do this. The first way is to copy it to the remote server with the following command:
Alternatively, you could first copy the file to the remote server with:
scp ~/.ssh/id_dsa.pub user@remoteserver:/your/home/directory
Then login to your remote server via ssh and copy the id_dsa.pub file into your authorized_keys file with the following command:
cat id_dsa.pub >> .ssh/authorized_keys
And that’s all there is to it. With this simple setup, you should now be able to login to your remote server via SSH without the need to enter a password.