Quick answer
How do I install Fail2ban on a VPS?
To install Fail2ban on a VPS, run apt install fail2ban (or dnf install fail2ban from EPEL), copy your settings into /etc/fail2ban/jail.local, enable the sshd jail, then restart and check it with fail2ban-client status sshd. Its defaults ban an address after 5 failed logins in 10 minutes, on a SaltVPS server as anywhere.
In brief
- What it does: reads login logs and bans addresses that fail too often, through the firewall.
- Where to configure:
jail.local, neverjail.conf, which updates overwrite. - Defaults: 5 failures within 10 minutes lead to a 10-minute ban.
- Debian 12 and 13: SSH logs go to the systemd journal, so set
backend = systemd. - Not a substitute for SSH keys: it cuts noise and slows guessing.
How do you install Fail2ban on a VPS step by step?
Commands for Ubuntu and Debian as root; AlmaLinux and Rocky Linux differences follow below.
Install the package
Run
apt updatethenapt install fail2ban.Create jail.local
Create
/etc/fail2ban/jail.local. Settings there override jail.conf and survive package updates.Set the defaults
Under [DEFAULT], set
bantime = 1h,findtime = 10mandmaxretry = 5. Add your own IP toignoreipif it is fixed.Enable the SSH jail
Under [sshd], set
enabled = trueandbackend = systemd. Addport = 2222only if SSH listens there.Start the service
Run
systemctl enable --now fail2ban, orsystemctl restart fail2banafter any edit.Check it works
Run
fail2ban-client status sshd. It shows failed attempts seen and the list of banned addresses.
Which Fail2ban settings should you change?
Four settings decide how strict the jail is; the defaults are mild.
| Setting | Meaning | Default | Stricter choice |
|---|---|---|---|
| maxretry | Failures allowed before a ban | 5 | 3 |
| findtime | Window in which failures are counted | 10m | 10m |
| bantime | Length of a ban | 10m | 1h or more |
| bantime.increment | Longer bans for repeat offenders | false | true |
| ignoreip | Addresses never banned | 127.0.0.1/8 ::1 | Add your fixed home or office IP |
How do you install Fail2ban on AlmaLinux or Rocky Linux?
Fail2ban comes from EPEL, the extra package repository for the Red Hat family.
dnf install epel-releasednf install fail2ban- write the same
/etc/fail2ban/jail.local systemctl enable --now fail2ban
The EPEL build works with firewalld, the default firewall there. The firewall guide covers firewalld and ufw basics.
Why does Fail2ban fail to start on Debian?
Recent Debian releases log SSH to the systemd journal, not to /var/log/auth.log. Fail2ban then finds no log file and stops. Setting backend = systemd in the [sshd] section fixes it. Run fail2ban-client -d to print the parsed configuration and catch typos, then read journalctl -u fail2ban for the error itself.
Is Fail2ban still worth it with SSH keys?
Yes, for quieter logs and less load, though keys do the real protecting. A key-only server refuses every password guess anyway. Fail2ban stops the same address from trying thousands of times. SaltVPS checked its checkout on 16 November 2026: a public key pasted there is installed for root, and password login then stays off.
Fail2ban is one step of the Linux VPS security guide. Do the sudo user step too, so root login can be turned off.
How do you see what Fail2ban has done?
Its client lists the active jails, and its log records every ban and unban.
fail2ban-client statusshows which jails are running.fail2ban-client status sshdgives the current and total counts of failures and bans for SSH.grep Ban /var/log/fail2ban.loglists each ban with its time and address.fail2ban-client get sshd bantimeconfirms the value really loaded from jail.local.
A jail with zero failures after a day on a public IPv4 usually means it reads the wrong log, not that nobody tried. Fail2ban updates arrive with the system packages, so the automatic updates guide keeps it current without extra work.
Fail2ban questions
How do I unban an IP address in Fail2ban?
Run fail2ban-client set sshd unbanip followed by the address.
I banned myself. What now?
Wait for bantime to pass, or connect from another IP and unban yours. Adding your fixed IP to ignoreip prevents a repeat.
Can Fail2ban protect nginx too?
Yes. It ships filters such as nginx-http-auth and nginx-botsearch; enable them in jail.local like the sshd jail.
What is the best Fail2ban config for SSH on Ubuntu?
maxretry 3, findtime 10m, bantime 1h with bantime.increment true, and backend systemd. Pair it with key-only login.
Does Fail2ban work over IPv6?
Yes. Versions from 0.10 onward ban IPv6 addresses as well as IPv4.
Verdict
- Installing Fail2ban on a VPS takes one package and a short jail.local.
- Use backend = systemd on Debian, and keep SSH keys as the main defence.
Sources (3)
- Fail2ban project and documentation — Fail2ban project (2026-11-16)
- jail.conf(5) manual page — Debian (2026-11-16)
- EPEL repository — Fedora Project (2026-11-16)
A key-only server from the start
Add your SSH key at checkout; Grain starts at $2.25 a month on 12 months.
- Built by a person, 1 hour at most after confirmation
- Lost days credited back if a server cannot be delivered
- Pay in BTC, XMR, USDT, USDC, ETH, SOL or LTC
- DomaineGoat LLC · Panama