SSH

Configure SSH Passwordless Logins between Linux servers

Share on Social Media

In this tutorial, you will learn, how to configure SSH Passwordless Logins between Linux servers. #centlinux #linux #ssh

Problem Statement

During automation of one server backups to another server known as, offsite backup, our transfer scripts get stuck at the password prompt during the execution of the copy/transfer commands, and the script remains stuck at the password prompt and do not execute any further until a password is provided. Although, it can be overcome by saving the passwords in the scripts, but it is not a recommended practice to save your password in clear text format.

Fortunately, there is a relatively better solution to this problem. We can use the RSA public key based authentication to setup ssh passwordless logins among two or more servers.

In this article, we will configure ssh passwordless logins between a Linux and a Ubuntu server.

Recommended Online Training: Learn Bash Shell in Linux for Beginners

Read Also: How to setup SSH Keys in PuTTY

System Specification

The machine on which we want to login without password.

Hostname: backupserver.test.local
IP Address: 192.168.229.128/24
Operating System: Ubuntu 14.04 LTS Server
Username: backupadm

The machine from which we want to login to backupserver.

Hostname: dbserver.test.local
IP Address: 192.168.229.133/24
Operating System: CentOS 6.5 Server
Username: oracle

Configure SSH Passwordless Logins

Connect to dbserver and generates a RSA public key without any passphrase.

$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/oracle/.ssh/id_rsa):
Created directory '/home/oracle/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/oracle/.ssh/id_rsa.
Your public key has been saved in /home/oracle/.ssh/id_rsa.pub.
The key fingerprint is:
ca:2a:87:fc:7b:98:ae:d7:95:b3:35:b3:36:89:db:b4 oracle@dbserver.test.local
The key's randomart image is:
+--[ RSA 2048]----+
|                 |
|                 |
|                 |
|                 |
|        S.       |
|     . .+ +      |
| . . +o. =.=     |
|  + =.o oo=.     |
|  .B=o  .oE.     |
+-----------------+

Above command generates two files in the ~/.ssh directory. Transfer the generated RSA public key id_rsa.pub file to backupserver.

$ scp .ssh/id_rsa.pub backupadm@backupserver:/home/backupadm/.ssh/rsa_dbserver_oracle
The authenticity of host 'backupserver (backupserver)' can't be established.
RSA key fingerprint is a2:38:20:d9:f6:93:04:fe:e5:09:cc:5d:b5:9a:7c:4c.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'backupserver' (RSA) to the list of known hosts.
backupadm@backupserver's password:
id_rsa.pub                                                           100%  409     0.4KB/s   00:00

Now, Connect to backupserver and merge rsa_dbserver_oracle into ~/.ssh/authorized_keys.

$ ssh backupadm@backupserver
$ cd .ssh
$ cat rsa_dbserver_oracle >> authorized_keys

Connect to dbserver and try to connect with backupserver.

$ ssh backupadm@backupserver
Welcome to Ubuntu 14.04 LTS (GNU/Linux 3.13.0-24-generic x86_64)
* Documentation:  https://help.ubuntu.com/
  System information as of Sat Apr  2 21:10:02 PKT 2016
  System load:  0.02              Processes:           246
  Usage of /:   3.6% of 36.54GB   Users logged in:     1
  Memory usage: 16%               IP address for eth0:192.168.229.128
  Swap usage:   0%
  Graph this data and manage this system at:
    https://landscape.canonical.com/
Last login: Sat Apr  2 20:26:45 2016 from dbserver

If you are new to Linux and facing difficulty in working at Linux Bash prompt. We recommend that, you should read The Linux Command Line, 2nd Edition: A Complete Introduction by William Shotts.

Conclusion

SSH Passwordless logins between Linux servers has been configured. Now our scripts do not stuck at password prompt.

Alaric Bird

Alaric Bird is a seasoned Linux System Administrator with over a decade of experience in managing and optimizing Linux-based servers and infrastructure. Known for his expertise in server deployment, security hardening, and performance tuning, Alaric has a deep understanding of various Linux distributions, including Ubuntu, CentOS, and Red Hat Enterprise Linux. His skills extend to cloud platforms like AWS, where he effectively manages virtual private servers and services. Alaric is also proficient in scripting languages such as Bash and Python, which he uses to automate routine tasks, enhancing efficiency and reliability. With a strong commitment to continuous learning, he stays updated with the latest developments in open-source technologies and best practices. His problem-solving abilities, combined with excellent communication skills, make him a valuable asset to any IT team. In addition to his technical expertise, Alaric is passionate about mentoring junior administrators and fostering a collaborative environment.

View Comments

Share
Published by
Alaric Bird

Recent Posts

Change Apache Document Root in Linux

Learn how to change Apache document root in Linux by following this step-by-step guide. Adjust…

2 weeks ago

How to Change Apache Port in Linux

Discover how to change Apache port in Linux easily. Follow our simple guide to modify…

2 weeks ago

How to Create Virtual Host in Apache Server

Learn how to create a virtual host in Apache Server with this comprehensive guide. Set…

3 weeks ago

10 Practical Tasks for RHCSA Exam with Solutions

Discover 10 practical tasks for the RHCSA exam with step-by-step solutions. Boost your Linux skills…

3 weeks ago

Ultimate Fail2ban Configuration Guide

Discover the ultimate Fail2ban configuration guide. Learn how to set up, customize, and optimize Fail2ban…

3 weeks ago

VPS Server: The Ultimate Guide to Virtual Private Servers

Explore the ultimate guide to VPS servers and learn everything about Virtual Private Servers, including…

4 weeks ago

This website uses cookies.