How to Connect|Configure two Linux machines using SSH keys

Soban Malik
4 min readFeb 3, 2024

--

If you need to log in to multiple Linux machines, doing it manually is a tedious and time-consuming task; why not use SSH Key-based authentication, which is safe and best for connecting multiple Linux machines?

SSH is a secure shell protocol that allows you to connect multiple Linux machines securely and remotely.

This tutorial will teach you how to connect two Linux machines using SSH keys. Let’s get started

Prerequisites

  • Two Linux machines(Machine A(server) and MachineB (client))
  • Administrative access to both servers

What are SSH keys?

SSH keys are sets of matching cryptographic keys used for authentication; one of them is the Private key, which is never shared with anyone and kept for your login purpose, and the other is the Public Key, which can be shared.

  1. First, install OpenSSH on both machines then on the Client machine write( sudo apt-get install OpenSSH-client), And on the server machine run (sudo apt-get install OpenSSH-server)

By default Linux has disabled SSH due to security reasons so first check the status(client machine as well as server machine)

2)Start and enable the SSH service

3)Then verify the name of the client and server machines using this command

4)When on the client side to connect through ssh first verify the fingerprint of the server(ssh server_machine_name with server IP)

5)Go to the server side and then type this command :


sudo ssh-keygen -l -f /etc/ssh/ssh_host_ecdsa_key.pub

6)Back to the client machine and type this command to connect to the server machine(ssh server machine name and IP)

7)The type on both machines ifconfig

8)Go the the configuration file to change the If u not need password authentication

9)Generate the key on the client machine

10)To verify the fingerprint of the key:

11)Install key on the server machine

12)To check the key on the server machine that I has installed or not

13)Now back to the client machine and connect it with the server machine(ssh server name and IP)

14)Make the dir on the client machine

15)Now on the server machine that is successfully created

By following these steps and considering the troubleshooting tips, you should be able to establish a passwordless SSH connection between your Linux server and client for secure and convenient remote access.

--

--

Soban Malik
Soban Malik

No responses yet