Installing Fail2ban on a VPS
Fail2ban monitors login logs and blocks IP addresses after several failed attempts — for example, when bots try to brute-force an SSH password.
Before configuring it, make sure you have access to the VPS console (VNC) in the client area: if you block your own IP, you can still log in through it.
1. Installation (Ubuntu, Debian)
apt update && apt install -y fail2banThe service starts automatically. For AlmaLinux and Rocky: dnf install -y epel-release && dnf install -y fail2ban && systemctl enable --now fail2ban.
2. Configuration
Put your own settings in /etc/fail2ban/jail.local — the main jail.conf file is overwritten during updates:
[DEFAULT]
bantime = 1h
findtime = 10m
maxretry = 5
ignoreip = 127.0.0.1/8 YOUR_IP
[sshd]
enabled = truemaxretry— how many failed attempts are allowed;findtime— the time window in which they are counted;bantime— how long to block;ignoreip— addresses that are never blocked: enter your permanent IP here.
Apply the changes: systemctl restart fail2ban.
3. Checking and unblocking
| Command | What it does |
|---|---|
fail2ban-client status | shows which protections (jails) are enabled |
fail2ban-client status sshd | shows how many and which addresses are blocked |
fail2ban-client set sshd unbanip 203.0.113.10 | unblocks an address |
Fail2ban complements your protection rather than replacing it: use SSH key login instead of a password.