Home / Articles / Fail2ban SSH Brute Force Protection on a VPS: Checklist
VPS / BUYING GUIDE

Fail2ban SSH Brute Force Protection on a VPS: Checklist

A server shielded from a swarm of key-shaped login attempts
Password guessing is background noise on any public IP — the ban only helps if the jail is actually watching the right log. Conceptual guide; commands are standard fail2ban.

Short answer: install fail2ban, enable the sshd jail against the log your SSH server actually writes to, set a ban time and retry limit you can live with, whitelist your own addresses, and confirm a ban triggers before you need it. A VPS with SSH on a public IP starts receiving password guesses almost as soon as it boots. Fail2ban does not make the server invisible — it watches the authentication log and blocks addresses that fail too many times, which turns a constant stream of guesses into occasional noise.

In this guide
  1. 1. Confirm the jail is watching the right log
  2. 2. Set limits you can live with
  3. 3. Whitelist your own addresses before you need them
  4. 4. Know how to recover from a self-lockout
  5. 5. Move towards key-only login
  6. Checklist before you move on

Fail2ban is a complement to key-only login, not a replacement for it. If password authentication is still enabled, a ban only slows an attacker down; the real protection is disabling password login entirely. The checklist below assumes you are moving towards keys, and it covers the fail2ban half of that setup.

1. Confirm the jail is watching the right log

The most common fail2ban failure is a jail that never sees a login attempt because it reads the wrong file. Depending on the distribution, SSH failures may land in the systemd journal or in a plain auth log, and the jail's backend must match. Check the jail status and confirm it is actually counting:

sudo fail2ban-client status sshd
sudo fail2ban-client status

If the jail shows zero failures after a day on a public IP, it is probably not reading the log — public servers attract attempts quickly, so silence is suspicious. Check which log the SSH server writes to and point the jail at it, then restart the service and watch the count move. If you are setting up a new server, our firewall first-steps guide covers the rules that belong alongside the jail, since fail2ban and the firewall do different jobs.

2. Set limits you can live with

The three numbers that matter are how many failures trigger a ban, over what window, and for how long the ban lasts. A low retry limit with a long ban time blocks attackers fast but also locks out a legitimate user who mistypes a password a few times; a generous limit with a short ban is friendlier and weaker. Pick values that match how you log in — if you always use keys, a strict limit costs you nothing, and if you sometimes type a password, leave room for a typo.

Also decide what the ban does. The default is a firewall rule that drops the address; some setups send a notification instead of or in addition to blocking. Either way, confirm the ban actually appears in the firewall after a test failure, because a jail that logs bans without applying them is just a diary.

3. Whitelist your own addresses before you need them

Add your own IP addresses and any jump host you use to the ignore list before the first real ban. Your home address may change, so note which addresses are whitelisted and review the list when your network changes. A static office IP belongs on the list; a shared VPN exit shared with strangers does not, since whitelisting it exempts everyone behind it.

Test the whitelist the same way you test the ban: trigger a few failures from a non-whitelisted address and confirm the ban lands, then trigger failures from a whitelisted one and confirm nothing happens. If the test that should ban does not, the jail is misconfigured — find out now, not after an attack.

4. Know how to recover from a self-lockout

Sooner or later you will ban yourself — a new device, a changed key, a mistyped password on a bad connection. The recovery path is the provider console, not SSH, so confirm before you need it that you can reach the console and that it works. Our SSH lockout recovery guide walks through console access and the steps to get back in when SSH refuses you.

From the console, check the ban list, remove your address, and fix whatever caused the lockout — a wrong key, a changed username, or a stale entry in your SSH config. If you find yourself unbanning the same address repeatedly, the cause is usually on your side: a script retrying with an old credential, or a tool hammering the server on a schedule.

5. Move towards key-only login

Fail2ban buys time; key-only authentication removes the target. Once fail2ban is running, disable password authentication in the SSH server configuration, restart the service, and confirm you can still log in with a key before closing the session you are working from. Keep a second key as a spare, stored separately, so a lost key is an inconvenience rather than a lockout.

If you rotate keys, do it deliberately rather than all at once: add the new key, confirm it works, then remove the old one. Our SSH key rotation guide covers the order of operations and the checks that keep a rotation from becoming a lockout.

Checklist before you move on

  • sshd jail enabled and reading the log the SSH server actually writes to.
  • Failure count moving: the jail has seen attempts since it started.
  • Retry limit, window, and ban time set to values that match how you log in.
  • Ban confirmed in the firewall after a test failure from a non-whitelisted address.
  • Own addresses whitelisted; console access confirmed for self-lockout recovery.
  • Password authentication disabled, key login confirmed, spare key stored separately.

Brute-force attempts are not a question of if — they start the day the server goes online. A jail that watches the right log, bans on a limit you chose, and leaves you a way back in turns that noise into a solved problem.

Article prices refer to the dated sources cited in the article. They may differ from current provider pricing. See how the numbers are made.