How to Setup SSH Login Without Password on RHEL 7

How to Setup SSH Login Without Password on RHEL 7
How to Setup SSH Login Without Password on RHEL 7

How to Setup SSH Login Without Password on RHEL 7 - Hello everyone, welcome to the blog. I hope you are all doing well and always blessed with ease in everything, be it in life or work. Amen.

In this discussion, I will explain how to set up an SSH login without a password on RHEL 7. The reason I am creating this post is that I received a task from my superior to set up a server, which will be used as a centralized location to collect backup data from various servers within the network.

Of course, manually transferring the data to the storage server would be time-consuming and require significant effort.

That's why I developed this automation. The main requirement is that the server holding the backup data can send it to the storage server without needing a login prompt, which typically involves entering a username and password.

How did I achieve this? I used the SSH key method, embedding the SSH key into the storage server so that the storage server trusts the incoming connection from the registered server or servers already whitelisted by the receiving server.

A brief explanation of SSH

ssh (SSH client) is a program for logging into a remote machine and for executing commands on a remote machine. It is intended to provide secure encrypted communications between two untrusted hosts over an insecure network. X11 connections, arbitrary TCP ports, and UNIX-domain sockets can also be forwarded over the secure channel.

ssh connects and logs into the specified hostname (with optional user name). The user must prove his/her identity to the remote machine using one of several methods.


Before we begin, I would like to remind you that when you follow my tutorial, it is better to try it in your own development environment or workstation first. Only when you are confident should you proceed with implementing it on the production server.

In the example case that I'm writing about, it goes like this: 'Here, I have prepared 2 servers, and I intend to schedule a backup of files from server 1 to server 2.' The following is the overview of what my goal will be once I have set up an SSH login without a password on RHEL 7.

How to Setup SSH Login Without Password on RHEL 7
How to Setup SSH Login Without Password on RHEL 7


Step One: Setup SSH Keygen

The first step is that you are required to generate an SSH key pair, which will result in a file that we will use to introduce this server to another server.

# ssh-keygen 
# press enter
# press enter
# press enter
Setup SSH Keygen
Setup SSH Keygen

After you run the command above, the file will be created inside the directory /root/.ssh/ if you generated it with the root user. If you are using another user, you can find the file in the home profile directory of the user you are using.

You can view the generated file using the ssh-keygen command in the specified path by executing:

# ls -la /root/.ssh/

Step Two: Copy

The next step is to simply send the generated file to the storage server where we will set up SSH login without a password. Here, I will be using the ssh-copy-id command for this purpose.
# ssh-copy-id -i ~/.ssh/ root@

Step Three: Hit Manual

After the copying process is completed and sent to the storage server or server 2, you can now try to log in to server 2. In this example case, server 2 has the IP address

Try ssh login from Server 1 to Server 2

# ssh -i ~/.ssh/id_rsa 
# ssh root@

if you used the other port can try this method

I have also added an option for cases where the destination server or storage server has an SSH port that is no longer the default 22 but has been customized to 5678.

To set up an SSH login without a password on RHEL 7, the login is provided with the option -p. Below is an example of how to use the command to transfer the file using a custom port.

# ssh-copy-id -i ~/.ssh/ "-p 5678 root@"

Make sure it Worked

Once you have successfully logged in to Server 2 ( without a password, you can now try to transfer files manually from Server 1 ( to Server 2 (

Below is an example of me copying the file "onemore.txt" using the scp command to the server with IP, using the root user, and placing it in the directory /home/:

# scp onemore.txt root@

Now, you can further enhance it by creating a bash script that contains the file transfer process, which you can then combine with your cronjob scheduling.

Closing statement

And that concludes my post on How to Setup SSH Login Without Password on RHEL 7. I hope this post can serve as a reference for you when you want to automatically backup a file from Server 1 to Server 2 without disrupting your time and effort, hehe.

Maybe that's all I can share with you guys, hopefully, this article will be useful.

Thank You 

Bangkit Ade Saputra
Bangkit Ade Saputra At the end of the day, my job involves people. we're complicated, we're always changing, we have millions of things going on in our lives, and changing jobs is always a big decision.

Post a Comment for "How to Setup SSH Login Without Password on RHEL 7"