Linux Server Hardening: 5 Steps to Stop Brute-Force Attacks

Bots are scanning your server's default SSH port this very second. Here's how to lock down Linux infrastructure before they get in.

Linux Server Security Isn't Boring—Here's Why Your SSH Port Is Being Attacked Right Now — theAIcatchup

Key Takeaways

  • Bots scan SSH port 22 millions of times daily—default settings are indefensible in 2024.
  • SSH hardening (key-based auth, custom port, disabled root login) eliminates the majority of brute-force attacks.
  • Zero-trust access via Cloudflare Tunnels makes your server invisible to port scanners, flipping the security model from perimeter defense to zero-exposure.
  • Automated patching and Fail2Ban turn defense into a set-it-and-forget-it process.
  • One hour of hardening prevents weeks of incident response and potential data loss.

Right now—as you’re reading this sentence—automated bots are battering default SSH ports on thousands of servers worldwide, trying random usernames and passwords like digital locusts. The numbers are staggering: some estimates put SSH brute-force attempts in the millions per day. Yet most Linux administrators still ship their servers with factory defaults, port 22 wide open, root login enabled, and password-only authentication. It’s like installing a bank vault and forgetting to close the door.

The problem? Linux server hardening isn’t sexy. It’s not a new framework or trendy language. But it’s absolutely everything—the difference between a server that hums quietly for years and one that becomes a zombie in someone else’s botnet before breakfast.

Why Your Default Setup Is a Liability

Server deployment has become trivial. Spin up an instance, run a few commands, deploy your app. But that convenience has a price: the moment your server gets an IP address, it’s visible to the internet’s scanning infrastructure. And the internet doesn’t poke gently.

“Security isn’t just a feature—it’s the foundation.”

That’s not hyperbole. A hardened system is the difference between infrastructure that works and infrastructure that survives. When you ship with defaults, you’re playing Russian roulette. Port 22 screams “try me.” Root login says “congratulations, here’s the kingdom.” Password auth? That’s inviting a brute-force orchestra to perform on your server’s front door.

And here’s what most people miss: the attackers aren’t smart. They’re automated. They’re scripts. Which means you don’t need to be smarter than humans—you just need to be less convenient than the default setup.

SSH Hardening: Stop Leaving the Keys Under the Mat

Your SSH configuration is the perimeter wall. If it’s weak, nothing else matters.

Start with the fundamentals. Disable root login entirely—PermitRootLogin no. This sounds aggressive, but it is the bare minimum. Even if someone cracks your password (and they will try), they can’t waltz in as root. They’d need a second exploit. Now you’ve doubled their work.

Next: kill password authentication. Replace it with Ed25519 SSH keys. Keys are mathematically harder to crack than passwords, and they can’t be brute-forced in any practical sense. Generate a key pair on your local machine, drop the public key on the server, and delete the password auth option. One line in /etc/ssh/sshd_config:

PasswordAuthentication no
PubkeyAuthentication yes

Then do something the bots absolutely hate: change the default SSH port. Moving from 22 to something like 2204 cuts port-scanning noise by roughly 90%. The bots are looking for port 22. Let them scan. You’re not there anymore.

Reload SSH, test the connection, and you’ve already eliminated three massive attack vectors.

How Does a ‘Default Deny’ Firewall Actually Protect You?

Think of a firewall as a security guard at the door of a nightclub. The guard’s job isn’t to let everyone in—it’s to keep everyone out unless they’re on the list.

UFW (Uncomplicated Firewall) makes this dead simple. Out of the box, it denies all incoming traffic. Then you explicitly open only what you need: port 2204 (your SSH), port 443 (HTTPS), maybe port 80 (HTTP). Everything else gets rejected.

sudo ufw default deny incoming
sudo ufw allow 2204/tcp
sudo ufw allow 443/tcp
sudo ufw enable

The beauty? It scales. Add a new service? Explicitly open its port. No service gets a free ride. This is the opposite of the default model, where everything’s open until you remember to close it. And people always forget.

Fail2Ban: Turning Automated Defense Into Routine

Even with SSH hardened, determined attackers will try. They’ll hammer your server with thousands of login attempts, hoping for a lucky break. Fail2Ban watches your logs in real-time and automatically bans IPs showing malicious behavior—multiple failed logins, SQL injection attempts, suspicious patterns. It jails them temporarily (or permanently, your choice), making them invisible to your server.

Set it up once. Forget about it. It works while you sleep.

Zero-Trust Access: Making Your Server Invisible

Here’s the mind-shift that separates 2024 thinking from 2015 thinking: why expose your SSH port to the public internet at all?

Cloudflare Tunnels (and similar tools) flip the model. Instead of inbound connections reaching your server, your server initiates an outbound encrypted tunnel to Cloudflare’s network. Access comes through their Zero Trust dashboard—you authenticate, authorize the user, and only then does the tunnel activate. Your server doesn’t have any open ports. Port scanners see nothing. It’s invisible.

This isn’t theoretical. This is what serious DevOps teams are doing now. It’s the industry moving toward zero-trust architecture because the old “firewall perimeter” model doesn’t cut it anymore.

Automated Patching: Stop Letting Software Rot

Security holes appear constantly. Kernel patches, library updates, service fixes—they’re released daily. Manually applying them is a losing game. You’ll forget. You’ll procrastinate. Someone else’s server will get compromised because you didn’t patch in time.

Enable unattended-upgrades and let it handle critical security patches automatically. Your server stays current. No human intervention. No excuses.

The Real Cost of Laziness

Neglecting hardening doesn’t feel dangerous until it’s too late. Your server seems fine. You’re shipping code. Everything works. Then one day you check your logs and realize you’re hosting someone else’s botnet, or your database got copied, or your AWS bill is $50,000 because your server’s mining cryptocurrency for criminals.

Hardening a server takes maybe an hour. Maybe two if you’re thorough. The cost of compromise? Weeks of recovery, loss of trust, potential legal liability, and the knowledge that your negligence hurt people who relied on you.

There’s no clever engineering here. No architectural insight. Just the unglamorous work of closing doors and monitoring for trouble. But that boring, foundational work is what separates infrastructure that’s secure from infrastructure that’s just lucky.


🧬 Related Insights

Frequently Asked Questions

How long does Linux server hardening take? Basic hardening—SSH config, firewall, Fail2Ban setup—takes 1-2 hours for a single server. Most of that’s testing. The actual implementation is maybe 20 minutes of commands.

Will changing the SSH port really stop attackers? It won’t stop sophisticated attackers, but it stops 90% of automated bot traffic. You’re not trying to stop every attacker; you’re making yourself a harder target than the default setup. Bots move on to easier prey.

Do I really need Cloudflare Tunnels if I have a firewall? No, but they solve different problems. A firewall controls what ports are open. Tunnels hide your server from the internet entirely. Use both for defense-in-depth. One is preventative, the other is evasion.

Marcus Rivera
Written by

Tech journalist covering AI business and enterprise adoption. 10 years in B2B media.

Frequently asked questions

How long does Linux server hardening take?
Basic hardening—SSH config, firewall, Fail2Ban setup—takes 1-2 hours for a single server. Most of that's testing. The actual implementation is maybe 20 minutes of commands.
Will changing the SSH port really stop attackers?
It won't stop sophisticated attackers, but it stops 90% of automated bot traffic. You're not trying to stop every attacker; you're making yourself a harder target than the default setup. Bots move on to easier prey.
Do I really need Cloudflare Tunnels if I have a firewall?
No, but they solve different problems. A firewall controls what ports are open. Tunnels hide your server from the internet entirely. Use both for defense-in-depth. One is preventative, the other is evasion.

Worth sharing?

Get the best AI stories of the week in your inbox — no noise, no spam.

Originally reported by Dev.to

Stay in the loop

The week's most important stories from theAIcatchup, delivered once a week.