Creating an SSH Connection to Remote Server

Hello devs in this tutorial i will discuss about how to ssh into a server using terminal. You know that SSH is an amazing way to make secure connections to servers.
It stands for Secure Shell and it's a network protocol between two computers

SSH gives us a secure connection between two network protocol. In today's article, I am going to show you how to set up an SSH connection to a server..

The basic command will look like this:

ssh [email protected]
// or
ssh [email protected]

 

We could do it with a password we set on the server, however in this case i don't want to do that. 

Generating the SSH key

Before we can do anything we need an SSH key to connect to the server. So we have to generate it. So let's open up the terminal and run the following command to generate  a new SSH key.

ssh-keygen -t ed25519 -C "[email protected]"

 

This will prompt the following options. See the below image and try it

how-to-connect-from-one-server-to-another-server-in-linux

 

Ok, Now we should have the public and private keys.

Setting the Authorized keys

Our server should have a ~/.ssh/ directory, if not you have to make it. Inside we should have or add the file: authorized_keys.

nano ~/.ssh/authorized_keys

 

No do the below step 

pbcopy < ~/.ssh/server_1.pub

 

Where server_1 is the name you gave your key. It will copy a string like that to your keyboard.

ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIH4TBYa16+8t9LJmqCuMjq+4PSxca81L8sN8OSgT5YW9 [email protected]

 

Connecting to the server with the SSH key

We have to add our new key with the following command

ssh-add -K ~/.ssh/server_1

 

Now time to test out our SSH key.

ssh [email protected]

 

Change the user and IP according to your server. Hope it can help you.

 

Facebook Github
A web enthusiastic, a self-motivated full-stack software engineer from Dhaka, Bangladesh with experience in developing applications using Laravel , React and Vue js