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
- Ubuntu / Debian
- AlmaLinux / Rocky
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.How to configure the SSH jail
Never editjail.conf: package updates replace it. Put your settings in jail.local, which overrides it.
1
Create jail.local
2
Add your settings
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
OK: configuration test is successful.4
Restart Fail2Ban
How to check it worked
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
sudo fail2ban-client status. To unban an address from all jails, run sudo fail2ban-client unban 203.0.113.10.
Frequently asked questions
Is Fail2Ban enabled for SSH by default on Ubuntu?
Yes. Aftersudo 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 calledsshd-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:
sudo fail2ban-client -t and restart Fail2Ban.
Why does Fail2Ban not start on Debian 12?
The errorHave 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.
Related guides
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:- Live Chat: Quick assistance via our website.
- Support Ticket: Open a Ticket
- Discord: Join our Community
- Email: support@freakhosting.com
Last Updated: November 2026