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 kitsake.com 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.
Preparation
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 |
Configure
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 |
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 id_rsa.pub
# ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.172.145
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 192.168.172.145.
Try ssh login from Server 1 to Server 2
# ssh -i ~/.ssh/id_rsa 192.168.172.145 # ssh root@192.168.172.145
if you used the other port can try this method
# ssh-copy-id -i ~/.ssh/id_rsa.pub "-p 5678 root@192.168.172.145"
Make sure it Worked
Once you have successfully logged in to Server 2 (192.168.172.145) without a password, you can now try to transfer files manually from Server 1 (192.168.172.144) to Server 2 (192.168.172.145).
Below is an example of me copying the file "onemore.txt" using the scp command to the server with IP 192.168.172.145, using the root user, and placing it in the directory /home/:
# scp onemore.txt root@192.168.172.145:/home
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
Post a Comment for "How to Setup SSH Login Without Password on RHEL 7"
Post a Comment