SSH Without Password in Linux/RHEL/Centos/Ubuntu

SSH Without Password in Linux

SSH Without Password in Linux/RHEL/Centos/Ubuntu Easy Steps

Here in our article, we will show you how to log in to another Linux machine using ssh secure key without a password. This ssh passwordless authentication will work on almost every Linux distribution RHEL, Centos, Fedora, Ubuntu.

Our Setup

In this setup, we will take the example of two machines and user explinux. you can do with root user too as per your requirement.
machine 1- 192.168.11.63 
machine 2- 192.168.11.65

Step – 1 Generate ssh-keygen key on – 192.168.11.63 

For this, you have to log in server with the user you want to do passwordless authentication and use below command to generate ssh-keygen:
[root@explinux ~]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):  press enter key
Enter passphrase (empty for no passphrase):  press again 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.
The key fingerprint is:
SHA256:hules3L8D52ayd2J248QqPGXZAtvbchWnyTUTHH51J4 root@explinux
The key's randomart image is:
+---[RSA 2048]----+
|               o=|
|              +.+|
|             . =o|
|       o   ..  Eo|
|      o S o +... |
|     . . + B Oo..|
|      ..+ o & o..|
|     ...o+ X * o |
|      .o..*.=.=..|
+----[SHA256]-----+

Step – 2 Create a directory for ssh on another machine 

Create a directory on the remote host where you will upload the generated authentication key.
[root@explinux ~]# ssh explinux@192.168.11.65 mkdir -p .ssh
explinux@192.168.11.65's password: Enter password

Step – 3 Copy generated keys to the second machine 

Copy the generated authentication key to another remote host 192.168.11.65 by below command
[root@explinux ~]# cat .ssh/id_rsa.pub | ssh explinux@192.168.11.65 'cat >> .ssh/authorized_keys'
explinux@192.168.11.65's password: Enter password 

Step – 4 Set Correct Permission on the Second Machine

Set the correct permission for keys. make sure you will do as shown below any incorrect permission will cause ssh error. 
[root@explinux ~]# ssh explinux@192.168.11.65 "chmod 700 .ssh; chmod 640 .ssh/authorized_keys"
If you have followed the upper steps correctly then this step will not prompt for the password.

Step -5 Now you can log in from machine 1(192.168.11.63 ) to machine 2(192.168.11.63 ) without any password 

[root@explinux ~]# ssh explinux@192.168.11.65
[explinux@localhost ~]#
Now you have successfully created passwordless authentication on the remote host. Now you can ssh, create a script without any issue or extra tool.
If you want to use our script for passwordless authentication: ssh passwordless script

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top