How to Connect to a Remote Computer/Server via SSH
Tags: ssh, remote, server
Published: 2021-06-19 19:24:51

---
title: How to Connect to a Remote Computer/Server via SSH
published: true
description: 
tags: ssh, remote, server
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s89iz0zde9drwks8dcou.jpg
---
{% youtube atubErtI33A %}

Secure Socket Shell commonly called SSH is a protocol that allows you to securely connect to a remote computer using the command-line interface(CLI). It’s so easy to set up and eliminates the need for manual logins.

Some of the reasons why you may be interested in setting up SSH are:
* You are a System admin, DevOps, or Backend engineer who wants an easier method to access your remote server or computer
* Or maybe you just want to learn how to do this for fun. No knowledge is a waste, and this may come in handy someday

This short article explains how you can quickly set it up an SSH connection to your remote machine.

## Basic requirements
Before starting with the setup procedure, please make sure you have the following:
1. Basic knowledge of the command line i.e bash
1. Local computer (your computer)
1. Remote computer
1. Network connection via the internet or LAN to the remote computer

## Connection steps
### On your local computer
On your local computer, open up a terminal and do the following steps.

1. Check if you have an existing ssh key
```sh
ls -ll ~/.ssh
```
If you already have SSH keys on your local computer you should see a file with one of the following names
```sh
Id_rsa.pub
id_ecdsa.pub
id_ed25519.pub
```
1. If you **do** have SSH keys **skip** to the next step. But if you don’t,  generate a new key by running the following command:
```sh
ssh-keygen -t ed25519 -C "put_your_email_address_here"
```
You should get a prompt saying: `Enter a file in which to save the key`. Press the `Enter Key` on your keyboard to use the default file location or enter a custom file name.

Then follow the prompt if you’d like to set a passphrase for your SSH key. You can skip this by hitting the `Enter key` twice.

1. Next, shart the SSH agent:
```sh
eval "$(ssh-agent -s)"
```
1. Then add your private key to the ssh-agent by running the below command. But If you supplied a custom file name(in step 2), replace id_ed25519 with it.
```sh
ssh-add ~/.ssh/id_ed25519
```
1. Lastly, copy the contents of the public SSH key to your clipboard. You can use the `cat` command to print out its content and then copy the output from the terminal:
```sh
cat ~/.ssh/id_ed25519.pub
```
Awesome! Now you have everything set on your local computer. Let’s move on to set up the remote computer.

### On the remote computer

Login into your remote computer and do the following steps on the terminal.

1. `cd` into your SSH directory:
```sh
cd ~/.ssh
```
1. Add your copied SSH key (from your local computer) to the  `authorized_keys` file
```sh
echo “put_your_public_ssh_key_here” >> authorized_keys
```
1. Restart the SSH service
```sh
sudo systemctl restart ssh
```
Now, you’re done setting up your remote computer. All you have to do is to connect to your remote computer from your local computer.

### Connecting to your remote computer
To connect to your remote computer, open a terminal on your local computer and run the code below and you should be connected:
```sh
ssh public_ip_of_your_remote_computer
```
## Have fun
Congrats you made it!

![you made it gif](https://media.giphy.com/media/3otPoS81loriI9sO8o/giphy.gif)

And that’s how to connect to a remote computer over SSH.

If you found this article helpful please leave a like. Also, check out [my awesome Youtube channel where I do all sort of fun tech stuff](https://youtube.com/confidenceokoghenun)