# How to install fail2ban?

> How to install fail2ban in 6 steps: apt install, a jail.local with the sshd jail on, the systemd backend, then the status and unban commands.

- URL: https://ironkvm.com/guides/how-to-install-fail2ban/
- Last updated: 2026-11-16
- Publisher: IronKVM (https://ironkvm.com)

fail2ban reads login failures and bans the addresses behind them for a while. One short jail.local file is all a VPS needs.

**Quick answer — How to install fail2ban?**

To install fail2ban, run apt install fail2ban, write /etc/fail2ban/jail.local with the sshd jail enabled, set backend = systemd on Debian 13, restart the service and check it with fail2ban-client status sshd. On an **IronKVM** VPS it takes 6 steps; the defaults ban an address after 5 failures in 10 minutes.

**In brief**

- fail2ban scans logs and bans addresses with too many failed logins, through firewall rules.
- Never edit jail.conf: put your settings in jail.local or jail.d.
- Defaults in jail.conf: bantime 10 minutes, findtime 10 minutes, maxretry 5.
- No jail is on by default: enable sshd yourself.
- The systemd backend reads the journal and needs the systemd Python library.

## Which fail2ban settings matter?

*Main fail2ban settings, their defaults in jail.conf and the values used in this guide, from the fail2ban project and its Debian manual*

| Setting | Default | This guide | Meaning |
| --- | --- | --- | --- |
| bantime | 10m | 1h | How long an address stays banned |
| findtime | 10m | 10m | Window in which failures are counted |
| maxretry | 5 | 5 | Failures that trigger a ban |
| backend | auto | systemd | Where log lines are read |
| enabled | false | true for sshd | Whether the jail runs |
| ignoreip | not set | your fixed IP | Addresses never banned |

## What are the steps to install fail2ban?

1. **Install the packages** — Install fail2ban and python3-systemd so the systemd backend can read the journal.
2. **Create jail.local** — Write your settings in /etc/fail2ban/jail.local. jail.conf may be replaced by package updates.
3. **Enable the sshd jail** — Set enabled = true and backend = systemd under [sshd].
4. **Whitelist your own address** — Add your fixed IP to ignoreip if you have one, so a typo never bans you.
5. **Start the service** — Enable fail2ban at boot and restart it to load the file.
6. **Check the jail** — Run fail2ban-client status sshd to see failures and banned addresses.

*Install and configure*

```bash
sudo apt install fail2ban python3-systemd
sudo tee /etc/fail2ban/jail.local <<'EOF'
[DEFAULT]
bantime  = 1h
findtime = 10m
maxretry = 5
ignoreip = 127.0.0.1/8 ::1

[sshd]
enabled = true
backend = systemd
EOF
sudo systemctl enable fail2ban
sudo systemctl restart fail2ban
```

*Check and unban*

```bash
sudo fail2ban-client ping
sudo fail2ban-client status
sudo fail2ban-client status sshd
sudo fail2ban-client set sshd unbanip 203.0.113.5
```

## Why use jail.local instead of editing jail.conf?

**Because package updates can overwrite jail.conf, while jail.local is never touched.** The header of jail.conf says not to modify it and to put changes in jail.local or a file in jail.d. The Debian manual page adds that .conf files should stay unchanged to ease upgrades.

Settings in jail.local override the same keys in jail.conf. You only write what you change. The [DEFAULT] section applies to every jail; a value under [sshd] applies to that jail only.

## Why set backend = systemd on Debian 13?

**Because the SSH server logs to the systemd journal, and this backend reads the journal directly.** The fail2ban manual says the systemd backend uses the systemd Python library to access the journal, and that logpath is not valid with it. The jail’s filter selects the right journal entries instead.

The default backend is auto, which tries pyinotify, then systemd, then polling. Setting systemd explicitly removes the guesswork. If `fail2ban-client status sshd` shows a file list and zero failures after a bad login, check the backend first.

## Is fail2ban still useful with SSH keys only?

**Yes, as a second layer: keys stop the guessing from working, fail2ban stops it from filling your logs.** With [SSH keys only](https://ironkvm.com/guides/how-to-set-up-ssh-keys-on-a-vps/ "How to set up SSH keys on a VPS?"), no password attempt can succeed. Bans still cut the noise and the load from scripts.

Pair it with the [UFW limit rule](https://ironkvm.com/guides/how-to-set-up-a-firewall-with-ufw/ "How to set up a firewall with UFW?"), which blocks fast bursts, while fail2ban handles slow, repeated failures. The [offshore VPS security guide](https://ironkvm.com/guides/how-to-secure-an-offshore-vps/ "How to secure an offshore VPS?") puts both in the right order.

fail2ban needs very little memory. According to IronKVM's survey of 16 November 2026, plans comparable to Billet cost a median of $15.00 a month; IronKVM Billet costs $4.46 on 12 months.

## fail2ban: questions

### What is the best bantime for fail2ban?

The default is 10 minutes. One hour is a common middle ground; longer bans mostly hit addresses that change anyway.

### I banned myself. How do I get back in?

Wait for the bantime, or log in from another address and run fail2ban-client set sshd unbanip with your IP.

### Can fail2ban protect nginx or WordPress?

Yes. It ships filters for many services; enable the matching jail in jail.local.

### Does fail2ban work with UFW?

Yes. Both add rules to the Linux packet filter and can run together.

### Does IronKVM install fail2ban for me?

No. Each VPS comes as a clean image of Debian 13, Debian 12, Ubuntu 24.04 LTS, AlmaLinux 10 and Rocky Linux 10.

**Verdict**

- **Two packages and one jail.local file** give a VPS automatic bans for repeated SSH failures.
- **Set backend = systemd on Debian 13** and check the jail with fail2ban-client status sshd.

## Sources

1. [fail2ban README](https://github.com/fail2ban/fail2ban) — fail2ban (read 2026-11-16)
2. [jail.conf (defaults)](https://github.com/fail2ban/fail2ban/blob/master/config/jail.conf) — fail2ban (read 2026-11-16)
3. [jail.conf(5), Debian trixie](https://manpages.debian.org/trixie/fail2ban/jail.conf.5.en.html) — Debian (read 2026-11-16)
4. [fail2ban-client(1), Debian trixie](https://manpages.debian.org/trixie/fail2ban/fail2ban-client.1.en.html) — Debian (read 2026-11-16)
5. [IronKVM offshore VPS survey (CSV)](https://ironkvm.com/data/ironkvm-offshore-vps-survey-2026-11-16.csv) — IronKVM (read 2026-11-16)

**Order a VPS and harden it** Billet, 1 vCPU, 2 GB RAM, 40 GB NVMe, 2 TB traffic, $4.46 a month on 12 months. [Order Billet](https://ironkvm.com/app/checkout/?plan=billet&term=12m&from=guide-fail2ban&lang=en) · [Compare the plans](https://ironkvm.com/pricing/ "IronKVM prices 2026: how much does an offshore KVM VPS cost?")

---

IronKVM: IronKVM is an offshore KVM VPS provider with servers in the Netherlands, Romania and Moldova that takes no action on DMCA takedown notices, for content that is legal in the server's country. It is paid in crypto with no ID upload and run by DomaineGoat LLC, a company registered in Panama. On the 12-month term each plan costs at least 25% less than a named comparable plan read on 16 November 2026.
