Apply for Free VPS

Block repeated sign-in attempts with Fail2ban

Updated 27 Nov 2026 security fail2ban

Install Fail2ban, protect SSH and check what has been blocked.

Fail2ban reads logs and temporarily blocks addresses that fail repeatedly. Keys with password sign-in turned off matter more; this reduces noise.

Install

sudo apt update && sudo apt install -y fail2ban      # Ubuntu, Debian
sudo dnf install -y epel-release && sudo dnf install -y fail2ban   # AlmaLinux, Rocky

Configure

Do not edit jail.conf. Create /etc/fail2ban/jail.local:

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

[sshd]
enabled = true
backend = systemd

Add your own fixed address to ignoreip if you have one.

Start and check

sudo systemctl enable --now fail2ban
sudo systemctl restart fail2ban
sudo fail2ban-client status sshd

Unblock an address

sudo fail2ban-client set sshd unbanip 198.51.100.7

On shared-IPv4 plans

Check that the logged client address is the real visitor's address before relying on bans, by looking at journalctl -u ssh.

Was this helpful?

Report outdated or incorrect information