VPSGauge

Fail2ban Setup on Ubuntu 24.04: Stop SSH Brute Force

Updated Nov 22, 2026 · by Kane · how we check

Part of New VPS setup, our guide to this topic

Short answer

To set up Fail2ban on Ubuntu, run sudo apt install fail2ban, put your overrides in /etc/fail2ban/jail.local (never jail.conf), enable the sshd jail, and check it with fail2ban-client status sshd. After that, Fail2ban bans IPs that fail to log in too many times.

Time
15 min
Steps
5
Works on
Ubuntu
24.04 LTS
On this page
  1. What Fail2ban does
  2. Before you start
  3. On Ubuntu: 5 steps
    1. 1Install Fail2ban
    2. 2Put your overrides in jail.local
    3. 3Restart the service
    4. 4Check the jail is watching
    5. 5Test a ban — and unban yourself
  4. Key takeaways
  5. A VPS for this guide
  6. If you ban yourself
  7. Common Fail2ban setup problems
  8. Questions

This guide has no affiliate links in the steps.

Fail2ban is the piece that watches your logs and blocks the bots hammering port 22. It comes after the firewall and the keys: finish the new VPS setup checklist first, log in with SSH keys and passwords off, and allow SSH in UFW — then point Fail2ban at the noise that’s left.

A monitor beside a server rack: Fail2ban reads the SSH login log, and after too many failed logins from one IP, it writes a firewall rule that blocks that IP for a while.

What Fail2ban does

Fail2ban is a log watcher with a short memory for repeat offenders. It tails a log file (or the systemd journal), counts failures per IP, and when one IP passes a threshold, it runs an action — usually a temporary firewall rule that drops that IP for a set time. The rule then expires on its own.

A Fail2ban setup has three named parts: a filter (the pattern that recognises a failed login), an action (what to do — here, ban through the firewall), and a jail (a filter plus an action pointed at one service, like sshd).

WHAT FAIL2BAN DOES 1 ATTACKER wrong passwords over SSH 2 SSH LOG written to the systemd journal 3 FAIL2BAN counts failures 5 in 10 min 4 FIREWALL banaction adds a block rule the ban lifts after bantime (10m by default)
WHAT FAIL2BAN DOES 1 ATTACKER wrong passwords over SSH 2 SSH LOG written to the journal 3 FAIL2BAN counts failures: 5 in 10 min 4 FIREWALL banaction adds a block rule the ban lifts after bantime (10m by default)

Before you start

You need four things:

  • A server running Ubuntu 24.04 LTS and a sudo user, with the OpenSSH server running. The steps also work on Debian 12, where the backend = systemd line below matters even more.
  • An SSH session to the server — or your provider’s web console, in case you lock yourself out.
  • Your own public IP to whitelist, so you never ban yourself. In the commands, YOUR_IP is a placeholder for it.
  • About 15 minutes. Step 5 is the one where a test ban happens on purpose.

Fail2ban setup on Ubuntu: 5 steps

Brute Force Protection with Fail2ban | Linux Security (HackerSploit, Akamai Developers) · YouTube (loads when you press play)
1

Install Fail2ban

serversudo apt update
sudo apt install fail2ban

Ubuntu 24.04 ships Fail2ban 1.0.2. The current package in noble-updates (1.0.2-3ubuntu0.1) fixes a Python 3.12 incompatibility in the original 1.0.2-3 build (Launchpad bug 2055114), so run apt update first. The package installs the fail2ban service; to be sure, start it now and set it to start on boot:

serversudo systemctl enable --now fail2ban

If it fails: Unable to locate package fail2ban. The package index is stale — run sudo apt update first, then install again.

2

Put your overrides in jail.local

serversudo nano /etc/fail2ban/jail.local

Paste this, replacing YOUR_IP with your own public IP:

jail.local — nano[DEFAULT]
bantime = 10m
findtime = 10m
maxretry = 5
backend = systemd
banaction = ufw
ignoreip = 127.0.0.1/8 ::1 YOUR_IP

[sshd]
enabled = true

Every edit goes in jail.local, never jail.conf. The jail.conf(5) man page says the .conf files can be replaced on upgrade and tells you to put changes in .local files. Fail2ban reads jail.local after jail.conf and jail.d/*.conf, so your values win.

The lines mean:

  • bantime = 10m, findtime = 10m, maxretry = 5 — these are Fail2ban’s own defaults, written out so you can see them: 5 failures in 10 minutes earns a 10-minute ban.
  • backend = systemd — read sshd’s login failures straight from the systemd journal, so Fail2ban doesn’t depend on a text log like /var/log/auth.log existing. Debian 12 no longer installs rsyslog by default (Debian 12 release notes), so there is often no auth.log at all.
  • banaction = ufw — match the firewall you run. If you followed our UFW guide, this is the override you need: bans then show up as rules in sudo ufw status, next to the rules you wrote. On a plain Ubuntu 24.04 box Fail2ban already ships defaults-debian.conf with backend = systemd, banaction = nftables and the sshd jail enabled, so if you don’t run UFW you can drop this line and keep nftables.
  • ignoreip — your own IP plus the loopback, so you never ban yourself.
  • [sshd] enabled = true — the sshd jail. Ubuntu 24.04 and Debian 12 both turn it on in defaults-debian.conf, but writing it here keeps the whole setup in one file.

Fail2ban’s stock jail.conf in Ubuntu 24.04: bantime = 10m, findtime = 10m and maxretry = 5 are highlighted, each under the comment that explains it. The stock defaults in jail.conf: 10m, 10m, 5. Source: git.launchpad.net (fail2ban, ubuntu/noble-updates), captured Nov 22, 2026.

Custom SSH port: if you moved SSH off port 22, add port = 2222 (your port) under [sshd] so Fail2ban bans the right failures. The default port is ssh, which resolves to 22.

The defaults-debian.conf file in Ubuntu 24.04’s fail2ban package: banaction = nftables, backend = systemd, and enabled = true under [sshd] are highlighted. What Ubuntu 24.04 already sets for you: nftables bans, the journal backend and an enabled sshd jail. Source: git.launchpad.net (fail2ban, ubuntu/noble-updates), captured Nov 22, 2026.

WHERE YOUR EDITS GO JAIL.CONF ships with the package JAIL.D/*.CONF Ubuntu defaults: systemd, nftables JAIL.LOCAL your overrides, read last YOUR VALUES WIN package updates rewrite jail.conf, they never touch jail.local Fail2ban reads jail.conf, then jail.d/*.conf, then jail.local — later files override earlier ones.
WHERE YOUR EDITS GO JAIL.CONF ships with the package JAIL.D/*.CONF Ubuntu defaults: systemd, nftables JAIL.LOCAL your overrides, read last YOUR VALUES WIN updates never touch jail.local Fail2ban reads in order: jail.conf, then jail.d/*.conf, then jail.local.
3

Restart the service

serversudo systemctl restart fail2ban

Restart picks up jail.local. The service is already enabled by the package; if systemctl is-enabled fail2ban ever says disabled, run sudo systemctl enable fail2ban.

4

Check the jail is watching

serversudo fail2ban-client status
sudo fail2ban-client status sshd

Check: status lists every jail; status sshd shows the filter, the action and two counts — “Currently banned” and “Total banned”. On a fresh server both start at zero.

5

Test a ban — and unban yourself

From a second machine (or a phone on cellular, not on your whitelist), fail to log in six times:

your computerssh user@YOUR_SERVER

Enter a wrong password each time. Then check:

serversudo fail2ban-client status sshd

Check: Your IP now appears under “Currently banned”, and real SSH logins from that IP are refused. Watch it live with sudo tail -f /var/log/fail2ban.log — that is the logtarget set in the package’s fail2ban.conf.

To lift the ban:

serversudo fail2ban-client set sshd unbanip YOUR_IP

Key takeaways

  1. Fail2ban setup is sudo apt install fail2ban, then your overrides in /etc/fail2ban/jail.local — never jail.conf.
  2. Ubuntu 24.04 already ships backend = systemd, banaction = nftables and an enabled sshd jail; the override most UFW users need is banaction = ufw.
  3. The defaults are bantime = 10m, findtime = 10m, maxretry = 5; whitelist yourself with ignoreip.
  4. Check it with sudo fail2ban-client status sshd; unban with sudo fail2ban-client set sshd unbanip YOUR_IP.
  5. If you ban yourself, the provider’s web console is the way back in.

A VPS for this guide

Everything above runs on any VPS with 1 GB of RAM. The cheapest 1 GB+ plan at each provider whose prices we read every day, IPv4 included:

Plan · providervCPU · RAM · diskYou payVisit
KVM VPS Special 1 GB
RackNerd · Los Angeles +19
1 vCPU·1 GB·20 GB$1.83/mo
VPS pico G11.5s
netcup · Nuremberg
1 vCPU·1 GB·30 GB$2.00/mo
SSD VPS 1
CloudCone · USA
2 vCPU·1 GB·30 GB$2.33/mo
1 slice
InterServer · New York +2
1 vCPU·2 GB·40 GB$3.00/mo
NVMe 2 GB
HostHatch · Amsterdam +15
1 vCPU·2 GB·10 GB$4.00/mo

Prices read Dec 4, 2026. gets that provider's deals on Telegram. Compare every 1 GB plan →

If you ban yourself

It happens: a mistyped ignoreip, a script that retries too often, and your own IP is in the jail. SSH is refused, so fix it through the provider’s web console — the browser-based VNC or SSH built into the panel. These consoles exist for exactly this.

Provider Web console What it is
DigitalOcean Recovery Console Out-of-band, works regardless of network settings
Vultr View Console noVNC terminal in the Vultr control panel
Hetzner Cloud Console (VNC) Console icon on the server page
OVHcloud KVM console KVM access from the control panel
Oracle Cloud Instance console connection Serial console, quickest through Cloud Shell
AWS Lightsail Browser-based SSH client Still SSH, opened from the Lightsail console, not VNC

From the console, log in and unban your IP — or just add it to ignoreip and restart:

sudo fail2ban-client set sshd unbanip YOUR_IP
sudo systemctl restart fail2ban

The cleaner fix is prevention: put your real IP in ignoreip before you turn anything on, and test from a different network.

LOCKED OUT? GET BACK IN YOU BAN YOUR OWN IP SSH is refused PROVIDER WEB CONSOLE browser VNC or SSH UNBAN THE IP set sshd unbanip YOUR_IP Whitelist your IP in ignoreip first, and this never happens.
LOCKED OUT? GET BACK IN YOU BAN YOUR OWN IP SSH is refused PROVIDER WEB CONSOLE browser VNC or SSH UNBAN THE IP set sshd unbanip YOUR_IP Whitelist your IP in ignoreip first, and this never happens.

Common Fail2ban setup problems

Fail2ban runs but never bans anyone.The jail is disabled, or the backend is looking at the wrong log. Check sudo fail2ban-client status sshd shows the jail, and keep backend = systemd so it reads the journal instead of a log file that may not exist.

Bans show in the jail but SSH still connects.Check the port line first: if SSH runs on a custom port and the jail still says ssh (22), the ban covers the wrong port. Then look for action errors with sudo grep -i error /var/log/fail2ban.log — a banaction whose tool isn’t installed fails there. Set banaction to the firewall you actually run (ufw or nftables).

You banned your own IP.Use the provider’s web console (above) and unban it, then add your IP to ignoreip.

Fail2ban doesn’t start after a reboot.The service isn’t enabled. Run sudo systemctl enable --now fail2ban.

The ban is too short.Raise bantime in jail.local, for example to 1h, and restart Fail2ban. A longer ban only helps once findtime and maxretry catch the failures in the first place.

Questions

What is Fail2ban?

Fail2ban is a service that watches log files or the systemd journal, counts repeated failures — wrong SSH passwords, repeated 404s — and bans the offending IP with a temporary firewall rule for a set time.

How do I view a Fail2ban jail?

Run sudo fail2ban-client status sshd to see one jail’s filter, action and ban counts, or sudo fail2ban-client status to list every jail on the server.

How do I stop the Fail2ban service?

sudo systemctl stop fail2ban stops it now, and sudo systemctl disable fail2ban keeps it off at boot.

Is there something better than Fail2ban?

The bigger wins come first: SSH keys with password login off stop brute force before Fail2ban ever sees it. Among the tools themselves, CrowdSec describes itself as “an open-source, lightweight security engine that detects and blocks malicious actors”, with shared community blocklists — but it’s a different tool, not a drop-in upgrade, and it doesn’t replace turning password login off.

How we checked: The commands, defaults and file names follow the Fail2ban jail.conf(5) man page and the source of the fail2ban 1.0.2-3ubuntu0.1 package in Ubuntu 24.04 (noble-updates): its jail.conf, fail2ban.conf, action.d/ufw.conf and jail.d/defaults-debian.conf, all read 2026-11-22. The provider web-console names come from each provider’s own documentation, read the same day. We did not run these steps on a test server for this guide, and a provider image with a customized config may differ. How we check.

Keep reading