Administration toolsCommands

SSH Passwordless Login Using SSH Keygen

SSH (Secure SHELL) is an open source and most trusted network protocol that is used to login into remote servers for execution of commands and programs. It is also used to transfer files from one computer to another computer over the network using secure copy (SCP) Protocol.
The below article clearly explains, how to generate the RSA ssh key and how to copy the ssh key to the remote server.

How to generate SSH Private/Public key

Use the below command to generate the RSA ssh key on your local server. Note that you are on the local server.

$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/rasho/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/rasho/.ssh/id_rsa.
Your public key has been saved in /home/rasho/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:+x60c3Htq3rJOFmXzv3MFbPKHT+dYBceRlsZVrtS+44 rasho@Gandalf
The key's randomart image is:
+---[RSA 2048]----+
|               o=|
|              .oo|
|              .oo|
|              .*o|
|        S . ..+==|
|         o . *.*=|
|        . + B BoB|
|         . B.+oXB|
|         .o.++EoO|
+----[SHA256]-----+
Generate ssh rsa key
Generate ssh rsa key

How to view generated SSH Private/Public key

The private/public key has been generated and stored at ā€œ/rasho/.ssh/ā€. Go to the corresponding directory and see the generated keys. See the output.

rasho@Gandalf ~ $ cd .ssh/
rasho@Gandalf ~/.ssh $ ls -la
total 16
drwx------  2 rasho rasho 4096 Feb 10 20:58 .
drwxr-xr-x 39 rasho rasho 4096 Feb 10 20:59 ..
-rw-------  1 rasho rasho 1675 Feb 10 20:58 id_rsa
-rw-r--r--  1 rasho rasho  395 Feb 10 20:58 id_rsa.pub

Copy the public key to remote host using ssh-copy-id

Iā€™m using ssh-copy-id to copy the id_rsa.pub key to the remote server.

# ssh-copy-id -i ~/.ssh/id_rsa.pub rasho@192.168.1.8
The authenticity of host '192.168.1.8 (192.168.1.8)' can't be established.
RSA key fingerprint is 5f:ac:09:45:65:b4:54:a1:bc:ff:ff:3c:5f:e9:5d:bd.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.1.8' (RSA) to the list of known hosts.
root@192.168.1.8's password:
Now try logging into the machine, with "ssh 'rasho@192.168.1.8'", and check in:

  .ssh/authorized_keys

to make sure we haven't added extra keys that you weren't expecting.

Try access Remote server without Password

$ ssh rasho@192.168.1.8
Last login: Fri Feb 10 14:28:49 2017 from 192.168.1.1

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.

Close
Close