Skip to content
10% off any project with promo code10% off with code

fail2ban Configuration: Protecting a VPS from Brute Force in 2025

Contents
  1. Installation
  2. Base configuration in /etc/fail2ban/jail.local
  3. WordPress protection (VPS without a control panel)
  4. The recidive jail — long bans for repeat offenders
  5. Checking it works
Published
Reading time
~1 min
Views
115
Reader rating
7 reviews
Author
Yevhen Fostenko
Senior Backend & DevOps Engineer
fail2ban Configuration: Protecting a VPS from Brute Force in 2025 Article
Need help with your website?
Describe the task on Telegram — I will assess it and suggest where to start. Reply within a day.
Message on Telegram
Free consultation and estimate. I reply quickly.

fail2ban is the first line of defence against automated attacks. Configured properly, it stops 99% of brute-force traffic.

Installation

apt install fail2ban
systemctl enable --now fail2ban

Base configuration in /etc/fail2ban/jail.local

[DEFAULT]
bantime  = 3600      ; 1 hour
findtime = 600       ; within 10 minutes
maxretry = 5
ignoreip = 127.0.0.1 1.2.3.4  ; your own IP

[sshd]
enabled = true
port    = 2222  ; if you changed the SSH port
logpath = /var/log/auth.log

[nginx-http-auth]
enabled  = true
logpath  = /var/log/nginx/error.log

[nginx-botsearch]
enabled  = true
logpath  = /var/log/nginx/access.log
maxretry = 2

WordPress protection (VPS without a control panel)

[wordpress]
enabled  = true
filter   = wordpress
logpath  = /var/log/nginx/access.log
maxretry = 3
bantime  = 86400

The filter in /etc/fail2ban/filter.d/wordpress.conf:

[Definition]
failregex = ^<HOST>.*"POST /wp-login.php

The recidive jail — long bans for repeat offenders

[recidive]
enabled  = true
logpath  = /var/log/fail2ban.log
bantime  = 604800  ; 1 week
findtime = 86400
maxretry = 3

Checking it works

fail2ban-client status
fail2ban-client status sshd

Need this set up? Order fail2ban configuration for your VPS.

Tags: fail2banvpslinuxsecuritybrute force
Need help with your website?
Describe the task on Telegram — I will assess it and suggest where to start. Reply within a day.
Message on Telegram
Free consultation and estimate. I reply quickly.

Related Articles

OpenCart Recovery After a Hack Article

OpenCart Recovery After a Hack

A hacked store is not only damaged reputation — it is a risk to customer data and a penalty from search engines. Recovery is not simply "remove the virus": i…

03/06/2026 176

Reader reviews

5.0
Write a review