# How do I install Fail2ban on a VPS?

> How to install Fail2ban on a VPS in 6 steps: install the package, write jail.local, protect SSH, start the service, check bans and unban.

- URL: https://saltvps.com/guides/how-to-install-fail2ban-on-a-vps/
- Last updated: 2026-11-16
- Publisher: SaltVPS (https://saltvps.com)

**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`, never `jail.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.**

1. **Install the package** — Run apt update then apt install fail2ban.
2. **Create jail.local** — Create /etc/fail2ban/jail.local. Settings there override jail.conf and survive package updates.
3. **Set the defaults** — Under [DEFAULT], set bantime = 1h, findtime = 10m and maxretry = 5. Add your own IP to ignoreip if it is fixed.
4. **Enable the SSH jail** — Under [sshd], set enabled = true and backend = systemd. Add port = 2222 only if SSH listens there.
5. **Start the service** — Run systemctl enable --now fail2ban, or systemctl restart fail2ban after any edit.
6. **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.**

*Main Fail2ban jail settings, default values and a stricter choice for SSH*

| 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-release`
- `dnf 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](https://saltvps.com/guides/how-to-set-up-a-ufw-firewall-on-a-vps/ "How do I set up a firewall on a VPS?") 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](https://saltvps.com/guides/how-to-secure-a-linux-vps/ "How do I secure a Linux VPS?"). Do the [sudo user](https://saltvps.com/guides/how-to-create-a-sudo-user-on-a-vps/ "How do I create a sudo user on a VPS?") 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 status` shows which jails are running.
- `fail2ban-client status sshd` gives the current and total counts of failures and bans for SSH.
- `grep Ban /var/log/fail2ban.log` lists each ban with its time and address.
- `fail2ban-client get sshd bantime` confirms 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](https://saltvps.com/guides/how-to-enable-automatic-updates-on-a-vps/ "How do I enable automatic security updates on a VPS?") 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

1. [Fail2ban project and documentation](https://github.com/fail2ban/fail2ban) — Fail2ban project (2026-11-16)
2. [jail.conf(5) manual page](https://manpages.debian.org/trixie/fail2ban/jail.conf.5.en.html) — Debian (2026-11-16)
3. [EPEL repository](https://docs.fedoraproject.org/en-US/epel/) — 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. [Order Grain for 12 months](https://saltvps.com/app/checkout/?plan=grain&term=12m&from=guides-how-to-install-fail2ban-on-a-vps&lang=en) · [All guides](https://saltvps.com/guides/ "Which VPS guides and Linux tutorials does SaltVPS publish?")

---

SaltVPS: SaltVPS sells Linux KVM VPS in New York, Dallas, Los Angeles, London, Amsterdam and Frankfurt, paid in crypto with no ID document. Seven plans from 2 to 32 GB of RAM cost the same in all six cities, and on the 12-month term each is priced at least 25% under a named comparable plan of a no-KYC crypto host, read on 16 November 2026. The operator is DomaineGoat LLC, Panama.
