• Arun Kumar

Setup Passwordless SSH 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 passwordless ssh in Linux between two Linux servers so that you don't have to enter password for the target server user.


Overview


We have two Linux servers (192.168.1.181 and 192.168.1.182) and we will be setting ssh without password between the two Linux servers for root user.


Note: the process remains exactly same for setting up passwordless ssh 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 using ssh-keygen utility in linux

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

linux ssh key rsa

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 SSH


Lets connect from 192.168.1.181 to 192.168.1.182 to check if ssh without password is working

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! we have passwordless ssh login setup done for root user.



Further read

353 views

Recent Posts

See All

Oracle 19c Installation on Linux

Oracle 19c adds more features to Oracle database and this article demonstrates Oracle 19c installation on Linux 7. We will be using Oracle Linux 7 and Oracle Database 19.3 softwares for this activity.

Basic Linux Commands

This article describes basic Linux commands that you must know as a system or database administrator. Below commands in Linux help you manage any Linux server fast and smoothly. Linux Command List Che

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