Skip to main content
To set up Fail2Ban for SSH on Ubuntu, install it with sudo apt install fail2ban, put your settings in /etc/fail2ban/jail.local (for example bantime = 1h, findtime = 10m, maxretry = 5), then restart it with sudo systemctl restart fail2ban. On Ubuntu and Debian the sshd jail is already enabled. Check bans with sudo fail2ban-client status sshd. Fail2Ban reads your login logs, counts failed attempts per IP address and adds a temporary firewall ban when an address fails too often. It slows down password-guessing bots. It does not replace SSH keys or disabling password login.

Before you start

  • You need root or a sudo user. Root users can leave out sudo.
  • Note your own public IP address so you can exclude it from bans.
  • If you ban yourself, you can unban from the VNC console. On a dedicated server, open a ticket if you need console access.
  • Run either Fail2Ban or CrowdSec for SSH, not both.

How to install Fail2Ban

The package enables the sshd jail in /etc/fail2ban/jail.d/defaults-debian.conf. On Ubuntu 24.04 that file also sets the systemd journal as the log source and nftables for bans.
Start Fail2Ban and enable it at boot:

How to configure the SSH jail

Never edit jail.conf: package updates replace it. Put your settings in jail.local, which overrides it.
1

Create jail.local

2

Add your settings

Replace 203.0.113.10 with your own IP address. If SSH runs on another port, set port = 2222 (your port number).
3

Test the configuration

The last line reads OK: configuration test is successful.
4

Restart Fail2Ban

How to check it worked

Example output:
Total failed rises as bots try passwords. If it stays at 0 while your auth log shows failures, see the FAQ below.

How to unban an IP address

To see every jail at once, run sudo fail2ban-client status. To unban an address from all jails, run sudo fail2ban-client unban 203.0.113.10.
If you ban your own IP, SSH stops answering from that address. Log in through the VNC console and run the unban command, then add your IP to ignoreip.

Frequently asked questions

Is Fail2Ban enabled for SSH by default on Ubuntu?

Yes. After sudo apt install fail2ban, the sshd jail is enabled with 5 attempts in 10 minutes and a 10-minute ban. Use jail.local to make bans longer.

Why does Fail2Ban not ban anything on Debian 13?

On newer OpenSSH releases, login failures are logged by a process called sshd-session, and the Debian service is named ssh.service, which older filters do not match (Fail2Ban issue 3747). Create /etc/fail2ban/filter.d/sshd.local with:
Then run sudo fail2ban-client -t and restart Fail2Ban.

Why does Fail2Ban not start on Debian 12?

The error Have not found any log file for sshd jail means Fail2Ban looks for /var/log/auth.log, which Debian 12 does not create because rsyslog is not installed by default. Add backend = systemd under [sshd] in jail.local, make sure python3-systemd is installed, and restart Fail2Ban (Fail2Ban issue 3292).

Does Fail2Ban work with UFW or firewalld?

Yes. On Ubuntu 24.04 it adds its own nftables table by default and works alongside UFW. On AlmaLinux and Rocky, fail2ban-firewalld sends bans through firewalld.

Do I need Fail2Ban if I only use SSH keys?

Bots cannot guess a key, but they still fill your logs and use resources. Fail2Ban cuts that noise. It matters most if password login is still on.

Can Fail2Ban protect other services?

Yes. jail.conf contains ready filters for services such as nginx, Apache and Postfix. Enable them in jail.local with enabled = true under the jail name.

VPS and dedicated server guides

Every guide in this section.

Install CrowdSec

Shared blocklists instead of Fail2Ban.

Disable password login

Stop password guessing for good.

Check login history

See failed SSH attempts.

Set up UFW

Firewall for Ubuntu and Debian.

Security checklist

Harden the rest of your server.

Checked against the official Fail2Ban project and its shipped jail.conf on 4 November 2026; installation, the jail.local and sshd.local examples (fail2ban-client -t) were tested on Ubuntu 24.04 LTS (Fail2Ban 1.0.2). Commands can differ on other distributions or releases.

Need Extra Help?

If you encounter any issues, our support team is ready to assist:

Save on Your Hosting

Ready to upgrade your hosting? Use code KB20 at checkout for 20% off your first order!

Last Updated: November 2026