Below are the steps to configure password less
authentication between two hosts.
Consider you are on "machine1.company1.com" and
you want to establish password less authentication on "machine2.company2.com"
for user "user2"
Follow the below 5 steps:
1. Log in to "machine1.company1.com" with user "user1".
Go to below directory:
cd /home/user1/.ssh/
2. Generate public-private key pair using below command.
Note: If you already have the public and
private keys in machine1 then step#2 can be skipped.
ssh-keygen -t rsa
Below
are the details needs to give for the command
·
Enter file in which to save the key
(/home/user1/.ssh/id_rsa):Press Enter (You can just press enter and accept the
defaults if you have no requirement to change the directory)
·
Enter passphrase (empty for no passphrase):
Press Enter
·
Enter same passphrase again: Press Enter
Your
identification (private key) has been saved in /home/user1/.ssh/id_rsa.
Your
public key has been saved in /home/user1/.ssh/id_rsa.pub.
Verify
the date of the above files.
3. SSH to other machine2 and perform below steps.
·
ssh user2@machine2.company2.com , enter the
password
·
cd /home/user2
·
Change .ssh directory to 700 permission (chmod 700 .ssh)
·
cd .ssh
·
Take the backup of authorized key file (authorized_keys authorized_keys_BKP)
·
Change authorized_keys to 600 permissions (chmod 600 authorized_keys)
4. Execute the below command from machine1.info.company1.com" with user "user1":
cat /home/user1/.ssh/id_rsa.pub |
ssh user2@machine2.company2.com 'cat >> .ssh/authorized_keys'
5. Close the current session and again log in to "machine1.company1.com" with user "user1"
Try ssh user2@machine2.company2.com
This
time it will not ask for the password.
That’s all
!!! You are done !!!
Happy coding, Happy Learning J J
thanks for sharing. it really helps!
ReplyDeleteVery helpful!! :)
ReplyDelete