# Fail2ban

> A tool that blocks an address when it fails to log in too often.

**Field:** Infrastructure  
**Category:** SSH & Remote Access  
**Also known as:** fail2ban, fail2ban-client, SSH Ban Tool

## Think of it like

Think of it like a guard at a door. Get the word wrong too many times, and he sends you away.

## Definition

Fail2ban is a tool that bans addresses that fail to log in too often. It reads the server's logs and counts failed logins. When one address fails too many times, it adds a firewall rule to block it for a while. It is most often used to guard SSH. It slows guessing down, but it does not replace keys.

## Example

A bot tries hundreds of passwords on Jack's server. Fail2ban spots it in the log and blocks its address at the firewall.

## Example code

```bash
sudo apt install fail2ban
sudo fail2ban-client status sshd
```

Install it, then ask which addresses the SSH guard has banned.

## Why it matters

It cuts the noise of attacks and blocks slow password guessing on any service with a log.

## Common mistake

Thinking fail2ban makes password login safe. A patient bot from many addresses still gets through, so use keys.

## Three principles

- **Reads logs.** Counts failed logins.
- **Bans at the firewall.** Blocks the address for a while.
- **Not a lock.** Keys still matter most.

## Related terms

- [SSH Password Authentication](https://learn.benibix.com/term/infrastructure/ssh-password-authentication)
- [sshd_config](https://learn.benibix.com/term/infrastructure/sshd-config)
- [Firewall](https://learn.benibix.com/term/infrastructure/firewall)
- [Uncomplicated Firewall (UFW)](https://learn.benibix.com/term/infrastructure/ufw)
- [journalctl](https://learn.benibix.com/term/infrastructure/journalctl)
- [Brute-Force Attack](https://learn.benibix.com/term/development/brute-force-attack)

## Taught in

- [sshd_config and Fail2ban](https://learn.benibix.com/learn/infrastructure-ssh/sshd-config-and-fail2ban): SSH, 6/9

![Bots on the left try many passwords against a server's SSH door. Inside the server, the file sshd_config has two switches turned off: password login and root login. A guard marked fail2ban reads the log, sees one address failing again and again, and bans it at the firewall. A laptop with a key gets in.](https://learn.benibix.com/diagrams/inf3-ssh-hardening.svg)

---

Source: https://learn.benibix.com/term/infrastructure/fail2ban
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-17
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
