How to Connect to a Remote Computer/Server via SSH

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
  2. Local computer (your computer)
  3. Remote computer
  4. 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
ls -ll ~/.ssh

If you already have SSH keys on your local computer you should see a file with one of the following names

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:
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:
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.
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:
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:
cd ~/.ssh
  1. Add your copied SSH key (from your local computer) to the authorized_keys file
echo “put_your_public_ssh_key_here” >> authorized_keys
  1. Restart the SSH service
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:

ssh public_ip_of_your_remote_computer

Have fun

Congrats you made it!

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

23