Tuesday, 20 March 2012

ssh-keygen: password-less SSH login

SSH is often used to login from one machine to another machine, There are number of methods to achieve this but mostly in every method it requires authentication..... It also does require authentication but for one time only i.e. for the first time you need to do a setup and for rest of the times when you will try to login via ssh it will not ask for any password.

you just need to generate your own personal set of private/public key pair. ssh-keygen is used to generate that key pair.

How to generate public/private key

root@server:/other_part# ssh-keygen -t rsa Press  (enter)
generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):   (save your default  on default location)
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.  (enter)
Your public key has been saved in /root/.ssh/id_rsa.pub.   (enter)
The key fingerprint is:
dc:20:59:db:43:6a:8c:52:7a:08:08:10:0b:eb:da:3d root@server
The key's randomart image is:
+--[ RSA 2048]----+
|Bo.   . . .      |
|oo . + = =       |
|o   + = * o      |
|.    o + o .     |
| .      S .      |
|.. .             |
|. . E            |
|     .           |
|                 |
+-----------------+
|++E...           |
|o.oo.            |
+-----------------+
Now copy private key on remote machine with below mention command

root@server:/other_part# ssh-copy-id -i /root/.ssh/id_rsa 172.27.24.75
root@172.27.24.75's password:  (Enter Password)
Now try logging into the machine, with "ssh '172.27.24.75'", and check in:
  ~/.ssh/authorized keys

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

While you are copying the private key then it will ask password.. Now try login again on remote machine it will not ask the password

root@server:/other_part# ssh 172.27.24.75
Last login: Wed Feb  5 12:36:46 2014 from server.oasis.com
[root@virtual ~]# 
njoy :)

1 comment: