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 user@server.domain.com
// or
ssh user@123.132.12.22

 

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 "you@email.com"

 

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 you@email.com

 

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 user@127.127.10.12

 

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

 

Facebook Github
A web enthusiastic, self-motivated Full-Stack Web Developer from Dhaka, Bangladesh with experience in developing applications using Laravel Vue and React Js Application.