Fail2Ban can temporarily block IP addresses after repeated SSH login failures. This example configures an SSH jail on a Debian or Ubuntu server that logs SSH authentication to the systemd journal.

Prepare access and install

Keep a working administrative session and console recovery access. Check compatibility with the existing firewall and security software; do not run competing firewall managers without confirming their integration.

sudo apt update
sudo apt install fail2ban python3-systemd

Do not upgrade every server package as an incidental step in installing one tool.

Configure the SSH jail

Create /etc/fail2ban/jail.d/sshd.local, or edit its existing SSH settings without introducing duplicate conflicting entries:

[sshd]
enabled = true
backend = systemd
port = 22
maxretry = 5
findtime = 600
bantime = 3600

Replace 22 if SSH uses another port. This example bans after five matching failures within ten minutes, for one hour. The systemd backend reads the journal and does not use logpath. A server logging only to files needs the appropriate file backend and real log path instead.

Validate and apply

sudo fail2ban-client -t

Only after validation succeeds, enable and restart the service:

sudo systemctl enable fail2ban
sudo systemctl restart fail2ban
sudo fail2ban-client status sshd

Check that the jail reads the expected SSH events and uses an action supported by the installed firewall. Do not assume iptables is the active backend.

Check recovery

If you conduct a controlled ban test, use a separate source address and retain an unblocked recovery session. To remove a confirmed test ban:

sudo fail2ban-client set sshd unbanip TEST_IP

Replace TEST_IP. Fail2Ban limits repeated failures; it does not replace secure credentials, patching or SSH policy. Imunify360 documents an incompatibility with Fail2Ban, so use its supported protection instead on those installations.