How to protect your server from brute-force attacks with fail2ban
Updated 7/20/2026
Any server with SSH open receives thousands of automated login attempts. fail2ban watches the logs and bans IPs that get the password wrong too many times.
1. Install
apt-get update -y
apt-get install -y fail2ban
2. Configure
Do not edit the default file; create /etc/fail2ban/jail.local:
[sshd]
enabled = true
maxretry = 4
bantime = 1h
findtime = 10m
After 4 wrong attempts in 10 minutes, the IP is banned for an hour.
3. Start the service
systemctl enable --now fail2ban
systemctl restart fail2ban
4. Check banned IPs
fail2ban-client status sshd
5. Unban an IP (if needed)
fail2ban-client set sshd unbanip 1.2.3.4
fail2ban can protect other services too (Nginx, WordPress). Combine it with SSH key authentication for the best protection.
Put this guide into practice on your own VPS
EU cloud servers, billed hourly, ready in minutes, with one-click installs for dozens of apps.
See pricingRelated tutorials
How to check which ports are open on your server
Find out which services are listening for connections on your server and close what you do not need, for less exposure.
Updated 7/20/2026SecurityHow to scan your server for malware with ClamAV
Install ClamAV, an open-source antivirus, and periodically scan your server for infected files.
Updated 7/20/2026SecurityHow to add security headers to your website
A few HTTP headers protect your visitors from common attacks like clickjacking and content injection.
Updated 7/20/2026