No KYC · seven Linux VPS plans, one price in six cities · Pay in BTC, USDT, USDC, ETH, SOL, LTC, XMR
Language: English
Configure a VPS

Guide · security · checked 16 November 2026

How do I install Fail2ban on a VPS?

Last updated: · 4 min read

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
SettingMeaningDefaultStricter choice
maxretryFailures allowed before a ban53
findtimeWindow in which failures are counted10m10m
bantimeLength of a ban10m1h or more
bantime.incrementLonger bans for repeat offendersfalsetrue
ignoreipAddresses never banned127.0.0.1/8 ::1Add 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 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 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 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)
  1. Fail2ban project and documentation — Fail2ban project (2026-11-16)
  2. jail.conf(5) manual page — Debian (2026-11-16)
  3. 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.

From $2.25/mo on 12 months · no KYC

Configure