How to ssh without password linux

By
Advertisement

Introduction:

In your practice you may need perform ssh without password in linux or you may need to do passwordless scp between two linux machines. For that you need to setup an ssh auto login password between two servers. You can perform passwordless scp and passwordless ssh, by configuring ssh auto login password.

Perform the below steps to configure ssh passwordless login in linux. Here, i am explaining the password less connection between two nodes, server1 and server2.

ssh without password linux:

Connect to server1 and run the below commands as a administrative user to establish the ssh connection without password from server1 to server2.

Step1: Run the below command as administrative user with which you want to make passwordless ssh connection. Hit Enter button when it prompts. Here am establishing ssh as oracle user.
Syntax: ssh-keygen -t rsa
[oracle@server1 ~]$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/oracle/.ssh/id_rsa): Enter⏎
Created directory '/home/oracle/.ssh'.
Enter passphrase (empty for no passphrase): Eneter⏎
Enter same passphrase again: Eneter⏎
Your identification has been saved in /home/oracle/.ssh/id_rsa.
Your public key has been saved in /home/oracle/.ssh/id_rsa.pub.
The key fingerprint is:
e6:fa:f6:92:0e:c9:50:b0:b2:03:a3:5a:a8:1c:58:1c oracle@server1.dbatalent.com
The key's randomart image is:
+--[ RSA 2048]----+
|  E .            |
| . . o           |
|o + . .          |
|o= o .           |
|+.+ .   S        |
|+... o +         |
|o.    + ..       |
|       o+        |
|      .+oo.      |
+-----------------+
[oracle@server1 ~]$

Step2: After generating public/private keys run the below command. Here Replace the IP address with your destination server IP(Here server2 for me). Enter the password for destinations server administrative user.
Syntax: ssh <Hostname / IP address> mkdir -p .ssh
[oracle@server1 ~]$ ssh 192.168.1.100 mkdir -p .ssh
oracle@192.168.1.100's password: 
[oracle@server1 ~]$

Step3: Now run the below command and enter the password for destination server user to copy authorized keys.
Syntax: cat .ssh/id_rsa.pub | ssh <hostname / IP address> 'cat >> .ssh/authorized_keys'
[oracle@server1 ~]$ cat .ssh/id_rsa.pub | ssh 192.168.1.100 'cat >> .ssh/authorized_keys'
oracle@192.168.1.100's password: 
[oracle@server1 ~]$ 

Step4: Now the below command to give the pemissions on authorized keys and enter the password when it prompts.
Syntax: ssh < hostname / IP address> "chmod 700 .ssh; chmod 640 .ssh/authorized_keys"
[oracle@server1 ~]$ ssh 192.168.1.100 "chmod 700 .ssh; chmod 640 .ssh/authorized_keys"
oracle@192.168.1.100's password: 
[oracle@server1 ~]$ 

Step5: Now verify the ssh passwordless login by making ssh connection from server1 to server2.
Syntax: ssh <hostname / IP address>
[oracle@server1 ~]$ ssh 192.168.1.100
Last login: Thu Feb 23 18:56:38 2017
[oracle@server2 ~]$ 
Now you are success fully completed ssh passwordless login. If you want make ssh passwordleass login from server2 to server1, then repeat the same 4 steps from server2.

0 comments:

Post a Comment