Home MiscellaneousHow to Set Up SSH Key Authentication Between Two Linux Servers

How to Set Up SSH Key Authentication Between Two Linux Servers

by SupportPRO Admin

If you manage multiple Linux servers, logging in with a password every time can be slow and insecure. A better method is to configure SSH key-based authentication. This allows secure login without entering a password each time.

In this guide, we will configure SSH access between two servers:

  • Server1 → Your server
  • Server2 → Remote server

Step 1: Login to Server1 as Root

First, log in to Server1 using SSH.

ssh root@Server1

Step 2: Generate an SSH Key Pair on Server1

Instead of using DSA (which is outdated), it is recommended to use RSA or ED25519 for better security.

Run the following command on Server1:

ssh-keygen -t rsa -b 4096

You will see:

Generating public/private rsa key pair. 
Enter file in which to save the key (/root/.ssh/id_rsa):

Press Enter to accept the default location.

Enter passphrase (empty for no passphrase):

You may:

  • Set a secure passphrase (recommended), or
  • Leave it empty for passwordless automation

After completion, you will see:

Your identification has been saved in /root/.ssh/id_rsa Your public key has been saved in /root/.ssh/id_rsa.pub

Step 3: Create .ssh Directory on Server2

Now create the .ssh directory on Server2.

You can do this directly from Server1:

ssh root@Server2 "mkdir -p /root/.ssh && chmod 700 /root/.ssh"

You will be asked for Server2’s root password.

Step 4: Copy the Public Key to Server2

Now copy the public key from Server1 to Server2:

cat /root/.ssh/id_rsa.pub | ssh root@Server2 "cat >> /root/.ssh/authorized_keys"

After entering Server2’s password, set proper permissions:

ssh root@Server2 "chmod 600 /root/.ssh/authorized_keys"

This step is important. Incorrect permissions may prevent SSH login.

Step 5: Test Passwordless SSH Login

Now try logging in from Server1 to Server2:

ssh root@Server2

If everything is configured correctly, you will log in without being asked for a password.

Why Use SSH Key Authentication?

  • More secure than password login
  • Protects against brute-force attacks
  • Useful for automation and scripts
  • Recommended for server-to-server communication

Important Security Tips

  • Disable password authentication after testing SSH keys
  • Avoid using root login directly in production
  • Use firewall rules to restrict SSH access
  • Regularly rotate SSH keys

If you need assistance configuring secure SSH access between your servers, contact SupportPRO Server Admin for expert support and server security guidance.

Facing issues?

Our technical support
engineers can solve it.

Contact Us today!
guy server checkup

You may also like

Leave a Comment