How to ssh without password linux



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/
The key fingerprint is:
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 mkdir -p .ssh
oracle@'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/ | ssh <hostname / IP address> 'cat >> .ssh/authorized_keys'
[oracle@server1 ~]$ cat .ssh/ | ssh 'cat >> .ssh/authorized_keys'
oracle@'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 "chmod 700 .ssh; chmod 640 .ssh/authorized_keys"
oracle@'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
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.

1 comment:

  1. Very informative article, which you have shared here about the passwordless ssh. After reading your article I got very much information and it is very useful for us. I am thankful to you for sharing this article here.