Skip to main content

Command Palette

Search for a command to run...

Beginner’s Guide to SSH: Secure Connections Without the Headache

Everything you need to know to start using SSH confidently.

Published
5 min read
Beginner’s Guide to SSH: Secure Connections Without the Headache
I

I am a Software Developer from Lagos, Nigeria.

If you have ever needed to access a computer remotely, like logging into your work computer from home, you know that keeping that connection secure is important. Passwords can be guessed, stolen, or intercepted.

That is where SSH (Secure Shell) comes in. It lets you connect to another computer (or a service like GitHub) safely without sending your password over the internet.


What is SSH?

Think of SSH as a secure, private tunnel between your computer and another computer. Instead of typing a password every time (which hackers could try to steal), SSH uses a pair of cryptographic keys to prove your identity.


A Simple Analogy: The VIP Party

Imagine you are trying to enter an exclusive VIP party:

  • Your Private Key → Your Secret Invite
    You keep this invite hidden and never show it to anyone.

  • Your Public Key → The Guest List
    Before the party, you send your invite details to the event organizers. They add your name (your public key) to the guest list.

At the door:

  • The bouncer doesn’t ask for your secret invite directly.

  • Instead, they give you a unique challenge — maybe they ask you to sign a note only you can sign with your invite.

  • You prove you have it without ever handing it over.

If your signature matches the guest list, the door opens.

That’s exactly how SSH works:

  • Private key stays with you. Never share it.

  • Public key goes to the server. Safe to share.

  • The server verifies you without ever seeing your private key.


How to Set Up SSH (Step by Step)

1. Generate an SSH key pair

Run this command:

ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
  • -t rsa → type of key (RSA).

  • -b 4096 → key strength (bigger is safer).

  • -C → comment to label the key.

This creates two files:

  • id_rsa → your private key (keep it secret).

  • id_rsa.pub → your public key (goes to the server or service).


2. Copy your public key to the server (and what this means for GitHub)

Your public SSH key is a small text file that proves “it’s you” when you connect to a server. The server needs a copy so it knows to let you in without asking for a password every time.

For GitHub:

  • You paste your public key into GitHub → Settings → SSH and GPG keys → New SSH key.

  • This tells GitHub: “This computer belongs to you.”

  • No need to type your username and password every time you push or pull code.

For a Linux server:

  • Instead of pasting manually, you can use:
ssh-copy-id user@server-address
  • This command logs into the server using your password (just once) and automatically adds your public key to the server’s ~/.ssh/authorized_keys file.

Result: From now on, you won’t need your password to log in — SSH will use your key automatically.

(In short: GitHub = paste key on website. Servers = ssh-copy-id does it automatically.)


3. Connect using SSH

ssh user@server-address

If everything is set up, no password is required. The server recognizes your private key and lets you in.


Using SSH with GitHub (From the Terminal)

Using SSH with GitHub means you won’t have to type your username and password every time you push or pull code.

Step 1: Generate a key (if you don’t already have one)

ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

Press Enter through the prompts to save it in the default location (~/.ssh/id_rsa).

Step 2: Start the SSH agent and add your key

eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa
  • The first command starts SSH agent, a program that securely holds your private key in memory.

  • The second command adds your private key to it, so you don’t have to type the passphrase every time.

Step 3: Copy your public key

cat ~/.ssh/id_rsa.pub

Copy the full text — this is what you will paste into GitHub.

Step 4: Add the key to your GitHub account

  • Go to GitHub → Settings → SSH and GPG keys → New SSH key.

  • Paste the key and save.

Step 5: Test your connection

ssh -T git@github.com

If it works, you will see:

Hi username! You've successfully authenticated.

What happens after successful authentication?

Once your key is set up, SSH works like a handshake:

  • Your computer says: “I’m user X — here’s proof using my private key.”

  • The server (or GitHub) checks its guest list (your public key in authorized_keys or GitHub settings).

  • If it matches, you are in — no password prompt needed.

  • On a server: You get a shell session. Your terminal prompt changes to the remote machine, and you can run commands as if you were sitting at that computer.

  • On GitHub: You don’t get a shell, but GitHub silently authenticates you. Push and pull commands (git push, git pull) now works without typing credentials.


Why Use SSH Keys (and the SSH Agent)?

  • No typing passwords → faster logins.

  • Much harder to hack → keys are long and complex.

  • Private key never leaves your machine → safer than sending a password.

  • SSH agent saves time → type your passphrase once per session instead of every time you connect.


Best Practices for Beginners

  • Always protect your private key with a passphrase.

  • Use ssh-agent only on your machine (not shared systems).


Conclusion

SSH keys are like VIP passes to your server or GitHub account:

  • The public key is on the guest list.

  • The private key proves your identity without revealing itself.

  • The SSH agent makes it convenient to use your keys without typing your passphrase repeatedly.

By switching from passwords to SSH keys and letting the SSH agent manage them, you make your connections safer, faster, and far more reliable.

My DevOps Journey

Part 5 of 8

I’m leveling up as a backend engineer by diving into DevOps. In this series, I will share what I learn — from basics to real-world use, so you can follow along, learn with me, or see DevOps through a beginner’s eyes.

Up next

🔐 Linux File Permissions — A Beginner-Friendly Guide

A simple guide to securing files on Linux