What Is SSH and Why You Need It
SSH (Secure Shell) is how you control a remote server from your own computer. If you ever rent a VPS, manage a home server, or work with any Linux machine that isn't sitting on your desk — you'll use SSH every day.
When we built a website on a $4 VPS, every command ran through SSH. When you follow our Docker guide, you'll SSH into your server to run containers. It's the single most important tool for server management.
SSH gives you: - A secure, encrypted connection to your server - A terminal session — just like sitting at the physical machine - File transfer capability (via SCP/SFTP) - Port forwarding and tunneling
The Simplest SSH Command
Here's the basic pattern:
ssh username@server-ip
Real example — connecting to a VPS at IP 156.226.181.250 as the root user:
ssh root@156.226.181.250
On first connection, you'll see:
The authenticity of host '156.226.181.250' can't be established.
ED25519 key fingerprint is SHA256:xxxx.
Are you sure you want to continue connecting (yes/no)?
Type yes. This only happens once — SSH saves the server's fingerprint so it can warn you if someone tries to impersonate the server later.
Then enter the password. You're in.
Connecting to a Specific Port
SSH defaults to port 22. If your server uses a different port (a common security measure), use -p:
ssh -p 2222 root@156.226.181.250
Before We Go Further: You Need Terminal Basics
If the commands above look foreign, spend 10 minutes with our Linux Terminal Basics guide first — it covers cd, ls, mkdir, and the 7 other commands you'll use constantly over SSH. Everything in this guide assumes you're comfortable typing commands into a terminal.
Password vs Key-Based Authentication
Password login: type a password every time. Simple, but vulnerable — bots constantly scan the internet trying common passwords against port 22.
Key-based login: you generate a pair of cryptographic keys (public + private). The server holds your public key; you hold the private key. SSH verifies they match without ever sending the private key over the network. It's both more secure AND more convenient — no password typing.
Every experienced server admin uses key-based auth. Let's set it up.
Setting Up SSH Key Authentication
Step 1: Generate a key pair (on YOUR computer)
ssh-keygen -t ed25519 -C "your-email@example.com"
-t ed25519— use Ed25519 algorithm (modern, fast, secure). Older guides say RSA; Ed25519 is better in 2026.-C "comment"— a label so you remember what this key is for.
Press Enter to accept the default location (~/.ssh/id_ed25519). Optionally set a passphrase for extra security (or leave empty for passwordless login).
This creates two files:
- ~/.ssh/id_ed25519 — your private key (never share this!)
- ~/.ssh/id_ed25519.pub — your public key (goes on servers)
Step 2: Copy the public key to your server
ssh-copy-id root@156.226.181.250
Enter your password one last time. This appends your public key to ~/.ssh/authorized_keys on the server.
Step 3: Test it
ssh root@156.226.181.250
If everything worked, you're in — no password prompt.
Step 4: (Optional but Recommended) Disable password login
Once key-based auth works, disable password login to stop brute-force attacks:
# On the server, edit the SSH config
sudo nano /etc/ssh/sshd_config
Find and change these lines:
PasswordAuthentication no
PermitRootLogin prohibit-password
Then restart SSH:
sudo systemctl restart sshd
⚠️ Warning: test that your key works BEFORE closing your current SSH session. If you lock yourself out, fixing it requires physical access to the machine (or VPS console from your provider).
Fixing "Permissions Are Too Open" Errors
If SSH rejects your key with a permissions error, it's because Linux SSH is strict about who can read your key files. This is closely related to the file permission concepts we cover in our chmod guide. Quick fix:
chmod 700 ~/.ssh
chmod 600 ~/.ssh/id_ed25519
chmod 644 ~/.ssh/id_ed25519.pub
This ensures only your user can read the private key, exactly what SSH demands.
The SSH Config File — Save Typing
Remembering IPs and ports is tedious. Create ~/.ssh/config on your local machine:
Host myserver
HostName 156.226.181.250
User root
Port 22
IdentityFile ~/.ssh/id_ed25519
Host homeserver
HostName 192.168.1.100
User admin
Port 2222
Now instead of:
ssh -p 2222 -i ~/.ssh/special_key admin@192.168.1.100
Just type:
ssh homeserver
You can also use these aliases with scp and rsync — they all respect the SSH config file.
Copying Files with SCP
SCP (Secure Copy) uses SSH to transfer files. Basic syntax:
# Local → Server
scp myfile.txt root@myserver:/home/user/
# Server → Local
scp root@myserver:/var/log/nginx.log ./downloads/
# Entire directories
scp -r ./myproject root@myserver:/home/user/
If you set up the SSH config file above, you can shorten this to:
scp myfile.txt myserver:/home/user/
Essential SSH Options Cheat Sheet
| Option | What it does | Example |
|---|---|---|
-p |
Specify port | ssh -p 2222 user@host |
-i |
Use a specific key | ssh -i ~/.ssh/custom_key user@host |
-v |
Verbose (debug) | ssh -v user@host |
-L |
Local port forward | ssh -L 8080:localhost:3000 user@host |
-R |
Remote port forward | ssh -R 8080:localhost:3000 user@host |
-N |
No commands (for tunnels) | ssh -N -L 8080:loc:3000 user@host |
Debugging SSH Connections
When things go wrong, add -v (or -vv or -vvv for more detail):
ssh -v user@host
Common problems and fixes:
| Symptom | Likely Cause | Fix |
|---|---|---|
Connection refused |
SSH not running on server, or wrong port | Check systemctl status sshd, verify port |
Connection timed out |
Firewall blocking, or server is down | Check firewall rules, ping the server |
Permission denied (publickey) |
Key not authorized or wrong permissions | Check ~/.ssh/authorized_keys on server, run chmod 600 on private key |
Host key verification failed |
Server changed (reinstall, IP reused) | Remove old key: ssh-keygen -R hostname |
Using SSH Tunnels (Port Forwarding)
SSH can forward ports, letting you access services on the server as if they ran locally:
# Make the server's port 3000 available at localhost:8080
ssh -L 8080:localhost:3000 user@server
Now open http://localhost:8080 in your browser — you're accessing the server's service through an encrypted SSH tunnel. This is great for:
- Accessing a database GUI on a remote server
- Browsing a web admin panel that isn't exposed to the internet
- Bypassing restrictive firewalls (only use on networks you own)
Keeping Connections Alive
SSH connections can drop if idle. Add this to ~/.ssh/config to prevent timeouts:
Host *
ServerAliveInterval 60
ServerAliveCountMax 5
This sends a keepalive ping every 60 seconds. After 5 failed pings (5 minutes), the connection drops.
Next Steps
Now that you can SSH into servers, here's where to go:
- Set up a VPS website from scratch — put your SSH skills to work
- Learn Docker — SSH into a server and run containerized apps
- Master the Linux terminal — the commands you'll type once you're in
- Turn an old PC into a home server — SSH into hardware sitting in your closet
SSH is a gateway skill. Once you can comfortably connect to a remote machine, the entire world of self-hosting, cloud servers, and system administration opens up. And it all starts with one command: ssh.