Guide

Fail2ban on a VPS

Last updated: 15 November 2026

Any server with a public SSH port is probed all day by automatic login attempts. Fail2ban watches the logs and temporarily blocks addresses that keep failing. It is a good extra layer, but SSH keys (guide) and a firewall (guide) come first. If you are logged in as root, leave out sudo.

Fast VPS from $7.99 a month

See Fast VPS plansHow ordering works

Install

sudo apt update
sudo apt install -y fail2ban

Configure SSH protection

Never edit jail.conf; create /etc/fail2ban/jail.local:

[DEFAULT]
ignoreip = 127.0.0.1/8 ::1 203.0.113.5
bantime  = 1h
findtime = 10m
maxretry = 5

[sshd]
enabled = true
backend = systemd
port    = ssh

Replace 203.0.113.5 with your own IP so a typing mistake cannot ban you (delete it if your home IP changes often), and change port if SSH runs on another port. Then:

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

Everyday commands

If you ban yourself, use the emergency console (VNC) on your service page, if it shows one, and unban your address there.

Related

First login · Docker on a VPS · Fast VPS

Questions and answers

What does Fail2ban do?
It reads the logs and temporarily blocks addresses that fail to log in too many times.

Is Fail2ban enough to secure SSH?
No. Use SSH keys and a firewall first; Fail2ban is an extra layer.

How do I avoid banning myself?
Add your own IP to ignoreip in jail.local.

How do I lift a ban?
Run sudo fail2ban-client set sshd unbanip ADDRESS.

Ready to try it? Fast VPS from $7.99 a month

See Fast VPS plansHow ordering works