I Locked Myself Out of My Server (Twice)

Jan 30, 2026 • Firewall / SSH

When I was still new to servers, I decided to “secure” my VPS by enabling a firewall. I ran ufw enable, felt like a cybersecurity boss… then logged out.

A few seconds later I tried SSH’ing back in and—nothing. I couldn’t access the server at all. I didn’t understand why.

So I did what any inexperienced person would do under pressure: I assumed the server was “broken”, destroyed the droplet, spun up a new one… and somehow made the exact same mistake again 🤦‍♂️


What actually happened

SSH runs on port 22. When you enable UFW, it blocks inbound connections by default unless you allow them first.

So by enabling UFW before allowing port 22, I basically told the server: “Block the door… then I walked outside.”

The correct order

Allow SSH first, then enable the firewall:

ufw allow 22/tcp
ufw enable


If you’re starting out and want a clean server to practice on: DigitalOcean free credits. And if you want a simple pre-hardening script (to avoid beginner traps like this): my Gumroad script.