Establishing Passwordless SSH Access between Servers Using Key Pairs

Photo by Carrie Johnson on Pexels
Published 3 February 2024 Last updated 3 February 2024 An older guide that hasn't been re-checked yet, so commands or versions may have moved on. How guides are made and checked

Setting up SSH access between servers using key pairs is a secure and efficient way to manage remote connections. This guide will walk you through generating SSH keys on your local machine and then using them to enable passwordless login to the destination server using ssh-copy-id.

Let’s Get Started

Step 1: Generate SSH Key Pair on Your Local Machine

On your local machine, open a terminal and use ssh-keygen to generate a new SSH key pair. This command will prompt you for a location to save the key and an optional passphrase for added security.

ssh-keygen -t rsa

Step 2: Copy the Public Key to the Destination Server

Copy the public key to the destination server using ssh-copy-id. Replace <your_username> and <destination_server> with your actual username and the IP address of the destination server.

ssh-copy-id <your_username>@<destination_server>

Step 3: Test SSH Access

Try SSHing into the destination server from your local machine. If successful, it should log in without prompting for a password.

ssh <your_username>@<destination_server>

Step 4: Disable Password Authentication (Optional)

For added security, consider disabling password authentication on the destination server. To do this, edit the SSH server configuration file:

sudo nano /etc/ssh/sshd_config

Then change PasswordAuthentication yes to PasswordAuthentication no. Finally, save and restart the SSH service:

sudo service ssh restart

Wrapping Up

Congratulations! You’ve successfully set up SSH access between your local machine and the destination server using SSH key pairs. SSH Key pairs enhance security and provide a more convenient and efficient way to manage your remote connections. Happy coding!

You May Also Be Interested In

Reading this guide from Ubuntu about SSH.