Guide
Set up fail2ban
Install fail2ban, write a jail, confirm the filter is matching real log lines, and whitelist your own address.
1. Install it
apt update && apt -y install fail2ban. The package ships a systemd unit, a filter library and an empty jail.local.
2. Write the jail
Create /etc/fail2ban/jail.local with [sshd], enabled = true, port = ssh, maxretry = 4, findtime = 10m, bantime = 1h. Never edit jail.conf, because the package overwrites it on upgrade.
3. Start and inspect it
systemctl enable --now fail2ban, then fail2ban-client status sshd. The output lists the filter, the log path and the current ban count.
4. Confirm the filter actually matches
grep 'Failed password' /var/log/auth.log should return lines. If it returns nothing and the jail sees no events, set backend = systemd in jail.local.
5. Escalate repeat offenders
Add bantime.increment = true and bantime.factor = 2. A second offense doubles the ban instead of restarting the same hour.
6. Whitelist your own address
ignoreip = 127.0.0.1/8 ::1 198.51.100.7 in jail.local. A typo in sshd_config behind an active ban is how a host becomes unreachable.
FAQ
Questions we get on this page
Does fail2ban stop a distributed attack?+
Can it ban on nginx 401 responses?+
Ready when you are
Tell us what you need. A human answers.
Pilot stage: one facility in Reykjavík, plans confirmed by hand, payment in crypto. Write to the desk and you get a real person, not a queue.