Tuesday, April 9, 2013

SSH Without password



Sometime in our unix environment we have a need to use ssh without password. In that case one user(suppose user91)  from server hostA wants to login to another server hostB without entering any password.  In that case, following steps can be performed to achieve the goal.


Generate public and private rsa keys:-
1.       Login to the server hostA with user91.
2.       Generate rsa key with following command :-

user91@hostA$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/user91/user91/.ssh/id_rsa): [Press enter key]
Enter passphrase (empty for no passphrase): [Press enter key]
Enter same passphrase again: [Press enter key]
Your identification has been saved in /user91/user91/.ssh/id_rsa.
Your public key has been saved in /user91/user91/.ssh/id_rsa.pub.
The key fingerprint is:
17:4d:74:24:24:8c:83:10:09:65:85:cc:fe:6b:85:9c user91@hostA
 
user91@hostA$ ls -lrt
total 4
-rw-------   1 user91 dba          887 Apr  8 16:52 id_rsa
-rw-r--r--   1 user91 dba          233 Apr  8 16:52 id_rsa.pub

Copy public key to the remote host 

Now create .ssh directory in the user91’s home directory of the other remote host server hostB. You can create the .ssh directory manually or through SSH login from hostA to hostB or through ssh-copy-id command.


user91@hostA$ ssh user91@hostB mkdir -p .ssh
user91’s password:
 
then copy id_rsa.pub keys to hostB and rename it to authorized_keys.
user91@hostA$ rcp id_rsa.pub hostB:/user91/.ssh/authorized_keys
user91@hostA$ rsh 10.2.2.1 chmod 600 /user91/.ssh/authorized_keys
user91@hostA$ rsh 10.2.2.1 chmod 700 /user91/.ssh
Or,
user91@hostA$ ssh-copy-id -i ~/.ssh/id_rsa.pub hostB
user91@hostB's password:
Now try logging into the machine, with "ssh 'remote-host'", and check in:
.ssh/authorized_keys
 
to make sure we haven't added extra keys that you weren't expecting.

Note: ssh-copy-id appends the keys to the remote-host’s .ssh/authorized_key. 

 The above two steps will be sufficient to enable ssh without password in most of the cases.

1 comment:

  1. Slingo Games Is a Brand New Game To Try In 2020 - Still
    But don't play Slingo? — If starvegad you're a ボンズ カジノ fan of classic games such as blackjack, ラッキーニッキー or baccarat, there's no better game than Slingo! Slingo is an

    ReplyDelete