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 fail2ban

The 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 = true
  • maxretry — 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

CommandWhat it does
fail2ban-client statusshows which protections (jails) are enabled
fail2ban-client status sshdshows how many and which addresses are blocked
fail2ban-client set sshd unbanip 203.0.113.10unblocks an address

Fail2ban complements your protection rather than replacing it: use SSH key login instead of a password.

Questions and answers
Log in through the VPS console in the client area and run fail2ban-client set sshd unbanip YOUR_IP. Then add your IP to ignoreip.
In /etc/fail2ban/jail.local. Do not edit jail.conf — it is overwritten during updates.