Server Security · 8 min read · Intermediate
VPS Hardening: SSH Keys & UFW Firewall
Lock down a fresh Ubuntu cloud droplet in 5 minutes using SSH keys, UFW firewall, and unattended security updates.
What you'll learn
- Generate ed25519 SSH keys (`ssh-keygen -t ed25519`)
- Restrict exposed ports strictly to 22, 80, and 443 with UFW
- Keep backend ports bound to `127.0.0.1` so the firewall never exposes them
Overview
Lock down a fresh Ubuntu cloud droplet in 5 minutes using SSH keys, UFW firewall, and unattended security updates.
Code Example
# Allow SSH, HTTP, and HTTPS before enabling firewall
ufw allow 22/tcp
ufw allow 80/tcp
ufw allow 443/tcp
ufw --force enable
ufw status
Key Takeaways
- Generate ed25519 SSH keys (
ssh-keygen -t ed25519) - Restrict exposed ports strictly to 22, 80, and 443 with UFW
- Keep backend ports bound to
127.0.0.1so the firewall never exposes them
Quick Check
Check Your Understanding
Score: 0 / 1
1. Why should backend APIs bind to `127.0.0.1:8787` instead of `0.0.0.0:8787`?
Study Workspace
Finished this lesson?
Your progress is saved locally in your browser, no account needed.