Even with everything else locked down, bots never stop trying passwords against port 22 — it's constant background noise and load. fail2ban watches your logs and automatically bans any IP that fails to log in too many times, so the attackers get shut out after a few tries instead of guessing forever. It's a small install and a big drop in log spam.
1. Install fail2ban
sudo apt update && sudo apt install -y fail2ban
2. Create a local config
Never edit the shipped jail.conf directly — override it in jail.local:
sudo tee /etc/fail2ban/jail.local > /dev/null <<'EOF'
[DEFAULT]
# don't ban yourself — add your home/office IP
ignoreip = 127.0.0.1/8 ::1
bantime = 1h
findtime = 10m
maxretry = 5
[sshd]
enabled = true
EOF
That bans an IP for an hour after 5 failed logins within 10 minutes. Add your own IP to ignoreip so a mistyped password never locks you out.
3. Start it and enable on boot
sudo systemctl enable --now fail2ban
4. Check the SSH jail
sudo fail2ban-client status sshd
You'll see how many IPs are currently banned — often a surprising number within minutes.
Managing bans
sudo fail2ban-client set sshd unbanip 1.2.3.4 # lift a ban
sudo fail2ban-client status # list all jails
sudo systemctl reload fail2ban # apply config changes
Honest cautions
- Add your own IP to
ignoreipso repeated typos don't ban you. If you do get banned, wait out the bantime or use a provider console — EQVPS gives every VPS one. - fail2ban complements, not replaces, SSH keys. Keys stop the guessing from ever succeeding; fail2ban stops the noise and guards other services too.
- Tune to taste: a longer
bantimedeters persistent attackers; too aggressive and you risk banning legitimate flaky connections.
Next steps
fail2ban is one layer of a hardened server. Combine it with SSH key authentication and a UFW firewall, and walk the full new-VPS security checklist before you expose anything to the internet.
Comments
No comments yet. Be the first.