How to use RSA keys for login to remote machines using SSH without Passwords on Ubuntu.

Hello Guyz… :).. Today In this tutorial I’m going to manage the remote Ubuntu/Linux machines via SSH key pairs. First of all let’s assume there are two Ubuntu servers are available, those are called QA-Server and PP-Server. (Please note, these all commands are run on QA-Server Terminal)

In order to create new user on QA-Serever the server use the following bash commands are used on QA-Serever.

$ sudo useradd -m -s/bin/bash <username>
$ sudo passwd <username>

Under the username you can add whatever the username and then add a relevant password for the created user.

As the first step you need to generate a RSA key pair which includes public key and the private key. The following bash command is used to generate key pair.

$ ssh-keygen -t rsa

Then you will see the following questions, then answer those clearly. In questions you will ask the directory where to store the key pair, paraphrases, etc. I f you are not willing to enter a paraphrase, let the field blank and enter. Finally you will see the following output.

Enter file in which to save the key (/home/qauser/.ssh/id_rsa):
Created directory ‘/home/qauser/.ssh’.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/qauser/.ssh/id_rsa.
Your public key has been saved in /home/qauser/.ssh/id_rsa.pub.
The key fingerprint is:
b6:73:c4:4d:bf:54:39:22:d3:b7:f7:6e:40:e9:cf:df qauser@QA-Server
The key’s randomart image is:
+–[ RSA 2048]—-+

Then we need to copy the id_rsa public key to the destination server, in my case I’m using PP-Server.

$ ssh-copy-id ppuser@PP-Server

Then you will get result like this.

Number of key(s) added: 1
Now try logging into the machine, with:   “ssh ‘ppuser@10.101.5.91′”
and check to make sure that only the key(s) you wanted were added.

Now you are eligible to login and execute bash commands on remote Ubuntu machines without passwords, as an example here is my loin.

$ ssh ppuser@PP-server “ifconfig”

Thank You….. 🙂

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s