Monday, September 1, 2014

SSH Passwordless Login Using SSH Keygen in 5 Easy Steps

First login into server 192.168.1.1 with user rajib and generate a pair of 
public keys using following command. 

[rajib@frombackup.com ~]$ ssh-keygen -t rsa

Generating public/private rsa key pair.
Enter file in which to save the key (/home/rajib/.ssh/id_rsa): [Press enter key]
Created directory '/home/rajib/.ssh'.
Enter passphrase (empty for no passphrase): [Press enter key]
Enter same passphrase again: [Press enter key]
Your identification has been saved in /home/rajib/.ssh/id_rsa.
Your public key has been saved in /home/rajib/.ssh/id_rsa.pub.
The key fingerprint is:
af:bc:25:72:d4:04:65:d9:5d:11:f0:eb:1d:89:50:4c rajib@frombackup.com
The key's randomart image is:
+--[ RSA 2048]----+
|        ..oooE.++|
|         o. o.o  |
|          ..   . |
|         o  . . o|
|        S .  . + |
|       . .    . o|
|      . o o    ..|
|       + +       |
|        +.       |
+-----------------+
 
 
Use SSH from server 192.168.1.1 to connect server 192.168.1.2 using sheena as user 
and create .ssh directory under it, using following command. 
 
[rajib@frombackup.com]$ ssh sheena@192.168.1.2 mkdir -p .ssh

The authenticity of host '192.168.1.2 (192.168.1.2)' can't be established.
RSA key fingerprint is d6:53:94:43:b3:cf:d7:e2:b0:0d:50:7b:17:32:29:2a.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.1.2' (RSA) to the list of known hosts.
sheena@192.168.1.2's password: [Enter Your Password Here]






Use SSH from server 192.168.1.1 and upload new generated public key (id_rsa.pub) on server 192.168.1.2 under sheena‘s .ssh directory as a file name authorized_keys.

[rajib@frombackup.com]$ cat .ssh/id_rsa.pub | ssh sheena@192.168.1.2 'cat >> .ssh/authorized_keys'
sheena@192.168.1.2's password: [Enter Your Password Here]
 
 
 
 
 
Due to different SSH versions on servers, we need to set permissions on .ssh directory and authorized_keys file.

[rajib@frombackup.com]$ ssh sheena@192.168.1.2 "chmod 700 .ssh; chmod 640 .ssh/authorized_keys" sheena@192.168.1.2's password: [Enter Your Password Here]



[rajib@frombackup.com]$ ssh sheena@192.168.1.2







for more : http://www.tecmint.com/ssh-passwordless-login-using-ssh-keygen-in-5-easy-steps/
 



No comments:

Post a Comment