DEV Community

Aditya Mhambrey
Aditya Mhambrey

Posted on

Secure Shell (SSH) for Newbs

Let's assume your Grandma who happens to live in Hawaii wants you to fix her 2003 HP laptop running Linux.
Grandma using SSH
Wouldn't it be easier for you to remotely login to her computer and apply the required changes?

I introduce you to my best friend - SSH to solve this problem at our disposal.

What is SSH?

  • Secure Shell is a way by which you can interact with remote machines over the internet.
  • Whether you're sending files, checking system stats, or fixing an issue, SSH lets you do all of this through the terminal—just like being there in person!

Why is it called "Secure" Shell?

  • SSH is "secure" because it uses encryption and authentication via a process called public key cryptography.
  • It's like you have two keys - Public Key is available for anyone to use while the private key is a secret kept by it's owner. Image description
  • The private key is the one which verifies the owner. Never give this key to anyone. It can become a severe issue.
  • The public key authenticates the connected devices in SSH, you still need to enter the username and password if the device is secured in order to connect. The public key is the padlock while private key is the actual key.

Using SSH

Both Linux and Mac, come with SSH installed by default. Windows users need to have an SSH client installed in order for SSH to work.
If you're a Chad, you are already using Linux, which means you can follow along with the article right away.

Note - Before we begin, you need the IP address of the computer you want to connect to.

Setting up Public/Private Keypair

Now, to securely connect to Grandma's computer in Hawaii, you'll need an SSH key pair. Think of it this way - you need a set of keys to get into Grandma's house, right? You wouldn’t just want some stranger walking in. Do the following:-

  • Open your terminal.
  • Type the following command.
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
Enter fullscreen mode Exit fullscreen mode

-t rsa: Specifies the type of key to create, in this case, RSA
-b 4096: The key is 4096 bits long
-C "your_email@example.com": Adds a comment, typically your email, to identify the key.

  • Press Enter to accept the default location (~/.ssh/id_rsa)
  • You can enter a passphrase to add an additional layer of security. Don't worry, it's optional, you can press Enter to skip this.
  • Once completed, your public key will be saved in ~/.ssh/id_rsa.pub, and the private key in ~/.ssh/id_rsa.

Connecting to a machine/server via SSH

Once you've finished with key generation of your SSH keys, you need to copy your public key to the server you want to access.

ssh-copy-id -i ~/.ssh/id_rsa.pub user@host
Enter fullscreen mode Exit fullscreen mode

{host} refers to the computer you want to access. This can be an IP Address (e.g. 192.168.10.12) or a domain name (e.g. www.xyz.com).
You are now ready to connect. You can do so with the following command:

ssh user@192.168.10.12
Enter fullscreen mode Exit fullscreen mode

Make sure to replace the above IP Address with the PC/Server's IP Address you want to connect to.
If you're connecting to that server for the first time, you will most likely see a prompt like The authenticity of host can't be established. Are you sure you want to continue connecting (yes/no)? Enter yes to continue connecting.

Hopefully, this post helped you in some way. I apologize for any errors that may have occurred while writing it. Thanks for reading my blog!

Top comments (2)

Collapse
 
atharvpatwardhan profile image
Atharv Patwardhan

Very informative!

Collapse
 
aditya_075 profile image
Aditya Mhambrey

Thank you for reading!