DEV Community

Cover image for How to connect to a remote server securely using Open SSH (Secure SHell)
tundek
tundek

Posted on • Updated on

How to connect to a remote server securely using Open SSH (Secure SHell)

In this article i will be explaining how we can connect to a remote server using the Open SSH (Secured Shell) protocol.

But before that, we will be getting some basic command checks out of the way.

First, we check the client PC to ensure the SSH directory is currently empty.

ls -latr ~/.ssh
Enter fullscreen mode Exit fullscreen mode

Output

Output of the above syntax

Step 1:

Generate the SSH key pair (SSH used the asymmetric cypher for encryption)

sudo ssh-keygen
Enter fullscreen mode Exit fullscreen mode

Output

Output of the sudo ssh-keygen command

If you noticed the above image, the SSH key pair was created in the /root/.ssh/ directory.

Checking the directory to see the files generated.

sudo ls -ltar /root/.ssh
Enter fullscreen mode Exit fullscreen mode

Output

Screenshot of the above command

We are done with the client Configuration, SSH on the client has now been installed

On to the Server now

Step 2:

Install the Open SSH Server software on the Server itself.

sudo apt install openssh-server -y
Enter fullscreen mode Exit fullscreen mode

Step 3:

Now we need to send/transfer the public key on the client computer to the Server using the command (utility tool on the client ssh) on the client:

sudo ssh-copy-id -i /root/.ssh/id_rsa.pub username@serverIPAddress
Enter fullscreen mode Exit fullscreen mode

sudo ssh-copy-id -i /root/.ssh/id_rsa.pub afeez@192.168.1.163
Enter fullscreen mode Exit fullscreen mode

You can use the ifconfig command to check the IP address of the server

The public key will now be transferred into the server.

To confirm this, run the command on the server.

ls -ltar ~/.ssh 
Enter fullscreen mode Exit fullscreen mode

Output

Comamnd output

To confirm the public key is the same you can run a cat command on both files

Final Step:

Connect to the remote server using the command:

ssh username@remoteserverIP
Enter fullscreen mode Exit fullscreen mode

ssh afeez@192.168.1.163
Enter fullscreen mode Exit fullscreen mode

Output

Ooutput

And BOOM!!!!

Output

We are now connected to the Sever using SSH.

I hope this helps.

Top comments (0)