If you run WordPress on your own VPS, bots are already knocking on your login page. Open your nginx access log and search for wp-login.php: on most small servers you will find hundreds or thousands of failed login attempts from IPs you have never seen. That is a brute-force attack, and the fix is not one tool but three layers working together: a strong password, two-factor authentication, and Fail2ban to stop wordpress brute-force attacks at the server level before they ever reach WordPress.
You need SSH access to your server and about 30 minutes. Everything here runs on Ubuntu 24.04 with nginx.
How to tell if bots are hammering your login page
Before you change anything, look at the evidence. A brute-force attack leaves a clear trail in your web server logs: the same IP address posting to /wp-login.php again and again, usually with a different username each time.
sudo grep "POST /wp-login.php" /var/log/nginx/access.log | tail -20
sudo grep "POST /wp-login.php" /var/log/nginx/access.log | awk '{print $1}' | sort | uniq -c | sort -rn | head -10
The first command shows recent login attempts. The second counts them per IP, so the worst offenders float to the top. If one IP has tried 50 or 100 logins in an hour, that is not a user who forgot a password. It is a bot cycling through common usernames like admin, administrator, and your site name. WordPress login attacks usually follow this pattern: common usernames first, then dictionary passwords, then leaked credentials from old breaches.
Check xmlrpc.php the same way. WordPress exposes an XML-RPC endpoint that accepts hundreds of login guesses in a single request, which makes it a favorite target. That is why an xmlrpc brute force attempt is so efficient: one request can test hundreds of passwords at once. If you do not use the WordPress mobile app or remote publishing tools, the safest move is to block it entirely, as explained in our guide on how to disable XML-RPC to stop wp-login brute-force attacks.
Step 1: Fix the password problem first
Fail2ban can slow an attacker down, but it cannot save a weak password. If your admin password is a dictionary word with a number at the end, a patient bot will guess it eventually, even with rate limits in place. Strong WordPress passwords start with three rules:
- Long and random. Use a password manager to generate at least 20 characters of mixed letters, numbers, and symbols. Memorize one master password, not fifty site passwords.
- Unique per site. Never reuse a password from another service. Credential lists from old breaches circulate for years, and bots test them against WordPress logins first.
- No shared admin accounts. Give every person their own account with only the role they need. Change the default
adminusername if it still exists, since it hands attackers half the answer for free.
Rotate the passwords for every account that can publish or administer the site. For a broader checklist of server-side habits that back this up, see our WordPress security basics for VPS owners.
Step 2: Turn on two-factor authentication
A strong password is one factor. Two-factor authentication (2FA) adds a second: a time-based code from an authenticator app on your phone. With 2FA on, a stolen password alone gets an attacker nowhere, because the login form also asks for a code that changes every 30 seconds.
Install a TOTP plugin, enable it for administrator accounts first, and test the login from a private browser window before you log out of your current session. Keep your recovery codes in your password manager: if you ever lose your phone, those codes are the only way back in without touching the database. Free TOTP plugins cover most sites; paid ones add login alerts and device management, so check official pricing before you buy.
Step 3: Stop WordPress brute-force attacks with Fail2ban
Now the server-side layer. Fail2ban watches your logs and bans any IP that fails too many logins in a short window, cutting off the attack at the firewall instead of letting WordPress handle each guess. Install it if it is not already on the server. If you already use it for SSH, you only need to add a WordPress jail; our Fail2ban setup guide for SSH brute-force attacks covers the base install.
sudo apt update && sudo apt install fail2ban -y sudo systemctl enable --now fail2ban
Create the filter at /etc/fail2ban/filter.d/wordpress.conf:
[Definition]
failregex = ^<HOST> .* "POST /wp-login.php
^<HOST> .* "POST /xmlrpc.php
ignoreregex =
Each match counts as a failure, so a bot that tries 50 passwords in a minute trips the limit fast.
Then add the jail to /etc/fail2ban/jail.local:
[wordpress] enabled = true filter = wordpress logpath = /var/log/nginx/access.log port = http,https maxretry = 5 findtime = 600 bantime = 3600 ignoreip = 127.0.0.1/8 ::1
That means 5 failed attempts within 10 minutes earns a 1-hour ban. You can raise bantime to 86400 (one day) later, but do not start there: a wrong setting locks real users out for a full day.
The logpath must point at the log your site actually writes to: /var/log/nginx/access.log on a default install, or your vhost log if the site uses one. If your site sits behind Cloudflare or another proxy, make sure nginx logs the real visitor IP rather than the proxy IP, or Fail2ban will ban the proxy and block everyone.
Restart Fail2ban and check that the jail is alive:
sudo systemctl restart fail2ban sudo fail2ban-client status wordpress
Test it safely: from a second connection, send six bad logins in a row, then run the status command again. Your test IP should now appear in the banned list. That is the whole point of a fail2ban wordpress jail: you proved it works before a real attacker shows up. For a deeper look at how jails, filters, and actions fit together, see our guide to Fail2ban jails for SSH, WordPress, and mail.
Step 4: Add nginx rate limiting as a second net
Fail2ban bans IPs after they fail. Rate limiting slows them down before they fail. Together they cover both fast attacks and slow ones that stay under the ban threshold by trying only a few passwords per hour. Define a limit zone in your nginx http block and apply it to the login location:
limit_req_zone $binary_remote_addr zone=login:10m rate=1r/s;
location = /wp-login.php {
limit_req zone=login burst=3 nodelay;
# ... your existing PHP handling
}
This allows one login request per second per IP, with a burst of three. A real user never notices, while a bot firing twenty guesses a second gets most of them answered with HTTP 503. Our walkthrough on how to rate-limit nginx to stop brute-force and scraping bots covers the tuning in more detail.
How to unban yourself and avoid locking yourself out
Sooner or later you will mistype your own password five times and ban your own IP. It happens to everyone who runs Fail2ban. You need one way into the server that does not depend on the website: SSH from another IP, a VPN, or your hosting provider console.
From that second connection, check the ban and lift it:
sudo fail2ban-client status wordpress sudo fail2ban-client set wordpress unbanip 203.0.113.10
Replace 203.0.113.10 with your own public IP, which you can find with curl -s ifconfig.me.
Better yet, add your home and office IPs to the ignoreip line in jail.local so Fail2ban never bans them:
ignoreip = 127.0.0.1/8 ::1 203.0.113.10
Restart Fail2ban after editing jail.local. A whitelisted IP is unprotected if it ever gets compromised, so whitelist only IPs you control and keep the list short. For a broader comparison of login defenses, including SSH keys and port knocking, see our guide on how to lock down your VPS login.
What to check after the first week
Let the setup run for a week, then look at what it caught.
sudo fail2ban-client status wordpress sudo grep "Ban " /var/log/fail2ban.log | tail -20
The status command shows current bans and the total since the jail started. A handful of bans a day from scattered IPs is normal background noise. The same IP returning every day, or dozens of fresh IPs in one hour, means someone is targeting you specifically: raise bantime and consider blocking the worst networks at the firewall.
Also re-check your access log. Failed logins should drop sharply once bans kick in, because banned IPs never reach WordPress. If the count stays high, check that Fail2ban is reading the right log file and that your filter regex matches your actual log format.
Brute-force protection is not a one-time fix. Review the jail every few months, keep WordPress and your server updated, and treat the three layers as a set: a strong password keeps guesses from working, 2FA makes a stolen password useless, and Fail2ban makes the guessing itself expensive. Together, they stop wordpress brute-force attacks from being a daily problem.