Skip to content
VDS · Security

Fail2ban against password brute force

How to install and configure Fail2ban: blocking SSH and web form brute force, whitelisting your own addresses, checking that it works, and unblocking yourself.

Updated August 23, 2026

Fail2ban reads logs, counts failed login attempts from a single address and temporarily blocks it with a firewall rule. It doesn't replace key-based login, but it removes most of the background brute-force traffic and takes load off your logs.

Installation and basic setup

apt install -y fail2ban

Use your own file, /etc/fail2ban/jail.local — edits to jail.conf are overwritten by updates:

[DEFAULT]
bantime = 1h
findtime = 10m
maxretry = 5
ignoreip = 127.0.0.1/8 203.0.113.5
banaction = ufw

[sshd]
enabled = true
port = 22
maxretry = 3
bantime = 24h
systemctl enable --now fail2ban
fail2ban-client status
fail2ban-client status sshd

Put your home or office address in ignoreip — this is your insurance against banning yourself. If your address changes, the console in the panel at /hosting/vds/m/<id> remains your safety net: it works regardless of the network and rules.

banaction must match your firewall: ufw for ufw, nftables-multiport for nftables.

Where to check the result

fail2ban-client status sshd
tail -f /var/log/fail2ban.log
journalctl -u fail2ban -n 50

The status shows the number of failed attempts and the list of banned addresses. On a public address, a daily count in the hundreds is normal, not a sign of a targeted attack.

Unban an address (including your own):

fail2ban-client set sshd unbanip 203.0.113.5

Protection beyond SSH

Fail2ban can work with any log that shows failed attempts.

[nginx-http-auth]
enabled = true

[nginx-limit-req]
enabled = true
logpath = /var/log/nginx/error.log

[postfix-sasl]
enabled = true

For your own application you'll need a filter — a file in /etc/fail2ban/filter.d/ with a regular expression in which the address is marked as <HOST>:

[Definition]
failregex = ^.*login failed.*ip=<HOST>.*$
ignoreregex =

Test the expression against a real log:

fail2ban-regex /var/log/myapp.log /etc/fail2ban/filter.d/myapp.conf

This command shows how many lines matched. Zero matches means the rule is wrong — and protection that silently fails is worse than none at all.

Common mistakes

MistakeConsequenceSolution
Edits to jail.confLost on updateWrite to jail.local
Your address not in ignoreipYou'll ban yourself one dayAdd it, or connect through the panel console
banaction doesn't match your firewallBans aren't appliedAlign it with ufw or nftables
Filter doesn't match the log formatSilence instead of protectionCheck with fail2ban-regex
Service can't read the systemd logEmpty statusSet backend = systemd

Test it for real: deliberately enter the wrong password the required number of times from an outside address and confirm it ends up in the banned list. An unconfigured fail2ban creates a false sense of security.

Round it out with connection rate limiting in the firewall itself — ufw limit 22/tcp.