Within minutes of a VPS getting a public IP, automated bots start guessing SSH passwords. Fail2ban has been the standard answer for years: simple, light and effective against brute-force attempts that leave traces in logs. It is not a complete security solution, but it reduces noise, slows attackers and protects services that must accept password logins. This guide covers a practical configuration.
Jails, Filters and Actions
- Filter: regular expressions that recognise failure lines in a log.
- Jail: combines a log path, a filter and settings such as how many failures within what time trigger a ban.
- Action: what happens on a ban, usually a firewall rule, optionally an email or webhook.
Fail2ban ships filters for many services (sshd, nginx-http-auth, postfix, dovecot and more). You configure jails in /etc/fail2ban/jail.local rather than editing the defaults.
Protecting SSH
Enable the sshd jail with sensible values, for example a ban after five failures within ten minutes, lasting one hour or more. Better still, disable SSH password authentication entirely and use keys (see our SSH keys guide); Fail2ban then mainly reduces log noise and blocks scanners. On systems using the systemd journal, configure the jail's backend to read the journal.
Key Settings
| Setting | Meaning | Typical value |
|---|---|---|
maxretry | Failures allowed before a ban | 3–5 |
findtime | Window for counting failures | 10m |
bantime | Ban duration | 1h or longer |
ignoreip | IPs never banned | Your office, VPN, monitoring |
banaction | Firewall integration | nftables, iptables or ufw |
Repeat Offenders
The recidive jail watches Fail2ban's own log and bans IPs that keep getting banned, for much longer (for example a week). It is an easy way to deal with persistent bots without making the first ban excessively long. Incremental ban times, where each repeat ban grows, achieve something similar.
Web Applications
- Use bundled filters for HTTP authentication failures and common bad bots.
- For application logins (WordPress, custom apps), log failed logins with the client IP in a consistent format and write a filter for it.
- If your site is behind a CDN or reverse proxy, log the real client IP; otherwise Fail2ban will ban the proxy.
- Consider rate limiting in Nginx for login endpoints as well.
Firewall Integration
Choose a ban action matching your firewall. With UFW, use the UFW action so bans appear alongside your rules (see our UFW guide). With nftables or iptables, use the corresponding actions. Bans should drop traffic from the IP to the relevant port, or to all ports for aggressive offenders.
Testing Filters
Use fail2ban-regex with a log file and filter to see how many lines match before enabling a jail. After enabling, use fail2ban-client status and fail2ban-client status sshd to see active bans, and unban test IPs with fail2ban-client set sshd unbanip.
Limitations
- Fail2ban reacts after failures appear in logs; it does not prevent the first attempts.
- Distributed attacks from many IPs with few attempts each may stay under thresholds.
- It does not stop DDoS floods, which need provider mitigation (see our firewall vs DDoS guide).
- For shared threat intelligence and multi-server bans, consider CrowdSec.
Monitoring
Review Fail2ban's log and ban counts periodically, send notable events to your log system or SIEM (see our Wazuh guide), and alert if the Fail2ban service stops.
Example: A Small Business Server
A VPS hosting a company website and mail server runs Fail2ban with jails for sshd (keys only, so mostly scanners), Postfix and Dovecot authentication, Nginx HTTP auth on the admin area and recidive with a one-week ban. The office IP and uptime monitor are in ignoreip. Authentication failures in the logs dropped by more than 90% within days.
Common Mistakes
- Editing jail.conf instead of jail.local, losing changes on upgrade.
- Forgetting ignoreip and locking yourself out.
- Banning the CDN or proxy IP instead of the client.
- Relying on Fail2ban while allowing SSH passwords.
- Filters that do not match the actual log format, so nothing is banned.
In Short
Enable the sshd jail, add jails for your other login points, tune retries and ban times, use recidive, whitelist yourself, test filters and pair Fail2ban with SSH keys, a firewall and provider DDoS protection.
Writing a Custom Filter
For an application login, first make the application log failures in a predictable line, for example a timestamp, the words "login failed" and the client IP. Create a filter file in filter.d with a failregex that matches that line and captures the host with Fail2ban's <HOST> placeholder. Run fail2ban-regex against a real log to confirm it matches failures but not successful logins, then add a jail pointing at the log with conservative retry and ban settings. Reload Fail2ban and trigger a few failures from a test IP to confirm the ban works before relying on it.
Next Steps
Disable SSH passwords, enable the sshd and recidive jails, whitelist your IPs, add jails for each login point, and test everything with fail2ban-regex and a test IP. Security tools are only as good as the people and routines around them, so assign an owner, schedule regular reviews and record what you change and why. Start small on one server, measure the results for a couple of weeks, and only then roll the same configuration out to the rest of your infrastructure, adjusting it for each server's role. When something unexpected appears, investigate calmly, preserve logs before changing anything, and write a short note afterwards about what happened, what you learned and what you changed to prevent it next time. If you are unsure where to begin, protect the services that face the internet first, such as SSH, administrative panels and login pages, because they receive the most automated attacks and give the quickest visible improvement.
SkyRainCloud Plans for This Workload
Fail2ban needs negligible resources and runs on any SkyRainCloud VPS alongside your applications.
AMD EPYC 7C13 VPS
Dedicated KVM vCores on AMD EPYC 7C13 (up to 3.70 GHz) with DDR4 ECC memory, NVMe SSD and an unmetered 1 Gbps port.
| Plan | vCores | RAM | Storage | Network | Price | Good for | Buy |
|---|---|---|---|---|---|---|---|
| VPS 1 — AMD | 2 | 8 GB DDR4 ECC | 40 GB NVMe SSD | 1 Gbps, unmetered | ₹649/month | Websites, small APIs, bots, staging and VPN servers | Order |
| VPS 2 — AMD | 4 | 16 GB DDR4 ECC | 80 GB NVMe SSD | 1 Gbps, unmetered | ₹1,299/month | WooCommerce, Node.js/Python backends, Docker Compose stacks, CI runners | Order |
| VPS 3 — AMD | 8 | 32 GB DDR4 ECC | 150 GB NVMe SSD | 1 Gbps, unmetered | ₹2,499/month | Production databases, high-traffic sites, multi-container apps | Order |
| VPS 4 — AMD | 16 | 64 GB DDR4 ECC | 250 GB NVMe SSD | 1 Gbps, unmetered | ₹4,899/month | Large production workloads, SaaS platforms, analytics, in-memory caches | Order |
Intel Xeon Platinum 8269CY VPS
KVM VPS on Intel Xeon Platinum 8269CY (up to 3.80 GHz Turbo) with DDR4 ECC memory, NVMe SSD, full root access and an unmetered 1 Gbps port.
| Plan | vCores | RAM | Storage | Network | Price | Good for | Buy |
|---|---|---|---|---|---|---|---|
| VPS 1 — Intel | 2 | 8 GB DDR4 ECC | 40 GB NVMe SSD | 1 Gbps, unmetered | ₹649/month | Business websites, small apps, scheduled jobs and bots | Order |
| VPS 2 — Intel | 4 | 16 GB DDR4 ECC | 80 GB NVMe SSD | 1 Gbps, unmetered | ₹1,169/month | Business software, mid-size databases, several sites on one server | Check stock |
| VPS 3 — Intel | 8 | 32 GB DDR4 ECC | 150 GB NVMe SSD | 1 Gbps, unmetered | ₹2,249/month | ERP/CRM stacks, heavier databases, multiple production apps | Check stock |
| VPS 4 — Intel | 16 | 64 GB DDR4 ECC | 250 GB NVMe SSD | 1 Gbps, unmetered | ₹4,299/month | High-memory workloads and consolidated production servers | Check stock |
Prices are monthly in INR as listed on the SkyRainCloud store (verified 2026-11-14). Stock and final pricing are shown on the product page at checkout.