SSH (Secured Shell) is a protocol which creates a cryptographically secured connection between the SSH client and remote servers. Using SSH you can manage and administer remote servers securely. This can be helpful in many ways.

Multi-server deployment Stop/start services remotely Automation

and all your creativity (hopefully)… As a sysadmin, this is kind of basic stuff to know. Let’s learn how… I will generate a private key and a public key. The private key should be stored on your ssh client machine and must be kept secured. The public key must be copied to the remote server to login to that server from the SSH client machine with no password required. You’ll learn the following.

Install SSH (not required if already installed) Generate SSH Keys Copy SSH Key to a remote server Log in to the remote server using SSH

For demonstration purpose, I have 2 servers with below IP addresses, one system is a client and the other one is a server on which I will log in through ssh from a client machine.

Client (user -> geekflare) : 192.168.56.102 Remote (user -> ubuntu) : 192.168.56.101

Installing SSH

Before you follow the steps mentioned in this article, make sure openssh-server is installed on the servers. If it is not installed, run the commands below to install. You can run ssh command to check whether it is installed on the system or not.

Generate SSH Keys

This needs to be done on a client server. Run the ssh-keygen command to generate a SSH key. Just press enter when it asks for the file, passphrase, same passphrase. It generates a pair of keys in ~/.ssh directory by default. Id_rsa is the private key and id_rsa.pub is the associate public key. It will generate two new files in ~/.ssh directory.

Copy SSH Key to Remote Server

The private key should be copied ~/.ssh folder on a remote server. Most of the servers should already have this folder if not, you need to create a folder. And, to do so:

Log in to the remote server with the user you would like to get connected. In my case, its ubuntu Ensure the present working directory is the user’s home directory and then create a .ssh folder. You can also use the following single command to create one

If you already have .ssh folder then take a backup of it. Next, let’s push the public key from a client server. On the client machine (192.168.56.102), run the command below to copy the public key on the remote server inside an authorized_keys file in .ssh directory. Run the command below to set permissions on the authorized_keys file on remote server. Great, this concludes key is exchanged and permission is all set.

Login to Remote Server using SSH

Let’s test to see if it works! Let’s login to the remote server (192.168.56.101) from a client machine (192.168.56.102) as geekflare user. Run the command below to test, it won’t ask password this time. Here you go… I have logged in to remote server successfully. Running below command will give the IP details of the remote machine. Conclusion Setting up SSH key exchange is very straightforward as you can see. I hope this helps you and interested in learning Linux administration and troubleshooting then check out this Udemy course.

How to Exchange SSH Key for Password less Authentication between Linux Servers  - 3How to Exchange SSH Key for Password less Authentication between Linux Servers  - 5How to Exchange SSH Key for Password less Authentication between Linux Servers  - 32How to Exchange SSH Key for Password less Authentication between Linux Servers  - 59How to Exchange SSH Key for Password less Authentication between Linux Servers  - 40How to Exchange SSH Key for Password less Authentication between Linux Servers  - 44How to Exchange SSH Key for Password less Authentication between Linux Servers  - 19How to Exchange SSH Key for Password less Authentication between Linux Servers  - 53How to Exchange SSH Key for Password less Authentication between Linux Servers  - 71How to Exchange SSH Key for Password less Authentication between Linux Servers  - 5How to Exchange SSH Key for Password less Authentication between Linux Servers  - 36How to Exchange SSH Key for Password less Authentication between Linux Servers  - 20How to Exchange SSH Key for Password less Authentication between Linux Servers  - 41How to Exchange SSH Key for Password less Authentication between Linux Servers  - 57How to Exchange SSH Key for Password less Authentication between Linux Servers  - 82How to Exchange SSH Key for Password less Authentication between Linux Servers  - 1How to Exchange SSH Key for Password less Authentication between Linux Servers  - 56How to Exchange SSH Key for Password less Authentication between Linux Servers  - 52How to Exchange SSH Key for Password less Authentication between Linux Servers  - 82How to Exchange SSH Key for Password less Authentication between Linux Servers  - 47How to Exchange SSH Key for Password less Authentication between Linux Servers  - 25How to Exchange SSH Key for Password less Authentication between Linux Servers  - 69How to Exchange SSH Key for Password less Authentication between Linux Servers  - 40