SSH


What is SSH?

Visual explanationarrow-up-right

SSH (Secure Shell) is a protocol that lets you securely access and control remote computers over a network. Think of it as a secure way to log into another computer and run commands as if you were sitting right in front of it.

What Problem Does SSH Solve?

Before SSH, people used Telnet and rlogin to remotely access computers. Just like FTP and HTTP, these sent everything in plain text - including passwords! SSH was created in 1995 to fix this massive security problem.

What SSH Does

SSH provides three main services:

Remote Command Execution - Run commands on another computer

Secure File Transfer - Transfer files (this is what SFTP uses)

Port Forwarding/Tunneling - Securely connect to services through an encrypted tunnel


How SSH Authentication Works

SSH offers two main ways to authenticate:

1. Password Authentication (Simple but less secure)

You type your password each time you connect. The password is encrypted, unlike Telnet.

2. Key-Based Authentication (More secure, no password needed!)

Uses a pair of cryptographic keys:

  • Private key - Stays on your computer (never share this!)

  • Public key - Goes on the server (safe to share)

Think of it like a lock and key: the server has the lock (public key), and only your key (private key) can open it.


Basic SSH Commands in Bash

Let me show you practical examples:

Example 1: Basic SSH Connection

What happens:

  1. You run the command

  2. SSH connects to the server

  3. You're prompted for a password (or uses your SSH key)

  4. You get a remote shell - you're now "inside" the remote computer!

  5. Type exit or press Ctrl+D to disconnect

Example 2: Run a Single Command Remotely

Example 3: Generate SSH Keys

Example 4: Copy Your Public Key to a Server

Example 5: File Transfer with SCP (SSH Copy)

Example 6: Interactive File Transfer with SFTP

Example 7: SSH Config File (Save Connection Details)

Example 8: SSH Tunneling (Port Forwarding)

Example 9: Keep SSH Connection Alive

Example 10: Real-World Deployment Script


SSH Security Best Practices

Use key-based authentication instead of passwords

Disable root login - edit /etc/ssh/sshd_config and set PermitRootLogin no

Change default port from 22 to something else (security through obscurity)

Use strong passphrases for your private keys

Keep your private key private - never share it or commit it to Git!

Disable password authentication once keys are set up: PasswordAuthentication no

Where SSH is Used

System Administration - Managing Linux/Unix servers

Web Development - Deploying websites and applications

Cloud Computing - Accessing AWS EC2, Digital Ocean droplets, etc.

Git Operations - GitHub, GitLab use SSH for secure code push/pull

DevOps - Automated deployments, CI/CD pipelines

IoT Devices - Managing Raspberry Pi, routers, embedded systems

Database Management - Secure remote database access


SSH vs Telnet: Why SSH Won

Feature
Telnet
SSH

Encryption

None

Full

Authentication

Plain text password

Keys or encrypted password

Port

23

22

Security

❌ Completely insecure

✅ Industry standard

Status

Dead/deprecated

Actively used everywhere

Telnet is to SSH what HTTP is to HTTPS - the old, insecure version that should never be used anymore.


Quick Troubleshooting

SSH is the backbone of modern server management and secure remote access. Once you get comfortable with it, you'll wonder how anyone ever managed servers without it!


Replaces older protocols: SSH was designed to replace older, less secure protocols like Telnetarrow-up-right and FTParrow-up-right that transmit data in plain text.


Explainer video


Last updated