• Arun Kumar

Setup Passwordless Connectivity in Linux

Every time you ssh from one Linux server to another, you need to enter target server user's password.


We can also setup password less ssh login between two Linux servers so that you don't have to enter password for the target server user.


Environment Overview


We have two Linux servers (192.168.1.181 and 192.168.1.182) and we will be setting password less connectivity between the two servers for root user. Our goal is to setup passwordless connectivity on both sides.


Note: the process remains exactly same for setting up passwordless connectivity for any other user in Linux.

Verify Existing SSH-Keys


It is a good idea to first check if ssh-keys are already generated on Linux server. You can always re-use the existing ssh keys and regenerating ssh keys will not be a good idea.


Let us check ssh-key on our servers (192.168.1.181 and 192.168.1.182)

On 191.168.1.181
================
ls -al ~/.ssh/id_*.pub

On 192.168.1.182
================
ls -al ~/.ssh/id_*.pub

If you see existing ssh keys then

Skip the next step and move to Add SSH-Keys

Else

proceed below!


Generate SSH-Keys


In each server, generate the ssh keys

On 192.168.1.181
================
ssh-keygen

Enter file in which to save the key (/root/ .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 /root/ .ssh/id_rsa. 
Your public key has been saved in /root/ .ssh/id_rsa.pub.

On 192.168.1.182
================
ssh-keygen

Enter file in which to save the key (/root/ .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 /root/ .ssh/id_rsa. 
Your public key has been saved in /root/ .ssh/id_rsa.pub.

Add SSH-Keys


View the ssh keys on 192.168.1.181 server and copy it to notepad

On 192.168.1.181
================
cat ~/.ssh/id_rsa.pub

View the ssh keys on 192.168.1.182 server and copy it to notepad

On 192.168.1.182
================
cat ~/.ssh/id_rsa.pub

Your keys must look like below on notepad


Copy the above keys from notepad and put it under .ssh/authorized_keys file on both server

On 192.168.1.181
================
vi ~/.ssh/authorized_keys     --> paste keys from notepad

On 192.168.1.182
================
vi ~/.ssh/authorized_keys     --> paste keys from notepad

Set Permissions


Give permissions to .ssh and authorized_keys file on both servers

On 192.168.1.181
================
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys

On 192.168.1.182
================
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys

Test Passwordless Connection


Lets connect from 192.168.1.181 to 192.168.1.182 server

On 192.168.1.181
================
ssh root@192.168.1.182

The authenticity of host '192.168.1.182 (192.168.1.182)' can't be established. ECDSA key fingerprint is SHA256:6yPNygL8ho6JKSlz54LFRzDSNf6UdBUQZcsWaqig738. ECDSA key fingerprint is MD5:c0:28:a8:2e:77:86:bb:cd:07:e4:c9:8e:3b:8f:de:43. [Enter yes Here] yes

Lets connect from 192.168.1.182 to 192.168.1.181 server

On 192.168.1.182
================
ssh root@192.168.1.181

The authenticity of host '192.168.1.181 (192.168.1.181)' can't be established. ECDSA key fingerprint is SHA256:6yPNygL8ho6JKSlz54LFRzDSNf6UdBUQZcsWaqig738. ECDSA key fingerprint is MD5:c0:28:a8:2e:77:86:bb:cd:07:e4:c9:8e:3b:8f:de:43. [Enter yes Here] yes

Done! your linux server is set for passwordless connectivity for root user.

Recent Posts

See All

Important Linux Commands

This article describes important Linux commands that you must know as a system or database administrator. Check CPU Cores in Linux Use one of the below commands to find number of CPUs in Linux includi

Manage Linux Firewall with iptables and firewalld

In this article will be covering details regarding iptables and firewalld which helps in Linux firewall management. We will also be looking at how to enable specific ports (1521 for Oracle) inside ipt

Mount Hard Disk in Linux

In this article we will be looking at adding a new hard disk to a Linux virtual machine and mount it on a directory. This can be achieved by adding a hard disk to virtual box machine under settings an

  • Facebook
  • Twitter
  • YouTube
  • Instagram

© 2020 by DBA Genesis

Feedback