---
title: "Brute-force protection for SSH and WordPress logins · CloudSat"
description: "Stop brute-force login attempts on SSH and WordPress: key-only SSH, sshd's built-in penalties, fail2ban jails, nginx rate limits on wp-login.php and XML-RPC."
url: https://cloudsat.io/learn/stop-brute-force-logins-on-ssh-and-wordpress
updated: 2026-11-18T12:00:00Z
source: CloudSat (https://cloudsat.io/). Prices in USD.
---

[Security](https://cloudsat.io/learn/topic/server-security)

# Brute-force protection for SSH and WordPress logins

Stop brute-force login attempts on SSH and WordPress: key-only SSH, sshd's built-in penalties, fail2ban jails, nginx rate limits on wp-login.php and XML-RPC.

CloudSat team November 18, 2026 7 min read

Every public server receives login attempts from the moment it gets an address. Most come from automated scripts that try common usernames and leaked passwords, on SSH and on web login pages alike. You cannot stop the attempts from arriving, but you can make them useless, slow and short-lived, in that order. This guide does it for the two targets hit hardest: SSH and WordPress.

| Layer | What it does | SSH | WordPress |
| --- | --- | --- | --- |
| Useless | Nothing guessable to guess | Keys only | Long unique passwords plus two-factor |
| Slow | Few tries per minute per address | sshd penalties, `MaxAuthTries` | nginx rate limit |
| Short-lived | Repeat offenders are blocked | fail2ban or CrowdSec | fail2ban filter on the access log |
| Invisible | The prompt is not public at all | Firewall source rules | IP allowlist for the admin area |

The order matters. Banning alone fails against attempts spread across thousands of addresses that each try only a few passwords, and no ban threshold catches that pattern. A key, or a password nobody can guess, does.

## Measure what you are dealing with

Read your own logs before changing anything, so you can see the effect later. On Ubuntu and Debian the SSH unit is `ssh`; on the RHEL family it is `sshd`:

```bash
sudo journalctl -u ssh --since today | grep -cE 'Failed password|Invalid user'
sudo journalctl -u ssh --since today | grep -oE 'from [0-9a-f.:]+' | sort | uniq -c | sort -rn | head
sudo grep -c 'POST /wp-login.php' /var/log/nginx/access.log
sudo grep -c 'POST /xmlrpc.php' /var/log/nginx/access.log
```

The first line counts failed SSH attempts today, the second lists the busiest source addresses, and the last two count login posts to WordPress.

## SSH: make guessing pointless

A password can be guessed. A key cannot. Once your key works, switch password and keyboard-interactive logins off and keep root restricted to keys:

```text
PasswordAuthentication no
KbdInteractiveAuthentication no
PermitRootLogin prohibit-password
```

The drop-in file to put them in, and the reload that applies them safely, are covered in [change the SSH port without locking yourself out](https://cloudsat.io/learn/change-ssh-port-safely). Then check what sshd actually uses, which catches settings that another file overrides:

```bash
sudo sshd -T | grep -E '^(passwordauthentication|kbdinteractiveauthentication|permitrootlogin|maxauthtries)'
```

With keys only, a brute-force attempt against SSH can no longer succeed, however long it runs. What remains is noise in the logs and a little CPU.

## SSH: use the penalties sshd already has

OpenSSH 9.8 added `PerSourcePenalties`, which is on by default. sshd remembers addresses that repeatedly fail authentication, connect without ever completing it, or crash the server, and refuses new connections from them for a while, longer for repeat offenders. Exempt your own management range so a script bug never shuts you out:

```text
PerSourcePenaltyExemptList 198.51.100.0/24
```

Check your version with `ssh -V`. Ubuntu 24.04 ships OpenSSH 9.6 and RHEL 9 ships 8.7, so they lack this feature and rely on fail2ban or CrowdSec for the same job. Debian 13 ships OpenSSH 10, which has it.

Two older settings still help. `MaxAuthTries 3` closes a connection after three failed attempts instead of six, and `LoginGraceTime 30` drops connections that sit at the login prompt for more than 30 seconds.

## SSH: ban repeat offenders with fail2ban

fail2ban reads logs, counts failures per address, and adds a temporary firewall ban when an address crosses the limit. Install it, then put your settings in `/etc/fail2ban/jail.local` so package updates leave them alone:

```bash
sudo apt install fail2ban
```

```ini
[DEFAULT]
bantime = 1h
findtime = 10m
maxretry = 5
bantime.increment = true
ignoreip = 127.0.0.1/8 ::1 198.51.100.24

[sshd]
enabled = true
backend = systemd
```

`bantime.increment` doubles the ban for addresses that come back. `backend = systemd` reads sshd's messages from the journal, which matters on systems such as Debian 12 and later that keep no `/var/log/auth.log` by default. `ignoreip` lists addresses that are never banned; put your own there.

```bash
sudo systemctl enable --now fail2ban
sudo fail2ban-client status sshd
sudo fail2ban-client set sshd unbanip 203.0.113.50
```

CrowdSec is the main alternative. It parses the same logs, blocks through a separate "bouncer" for the firewall, and can share signals with other users of the project so that known sources are blocked before they reach you.

## WordPress: rate-limit the login page

WordPress has no built-in limit on login attempts. nginx can add one in front of PHP, before WordPress spends any time checking a password. This version counts only `POST` requests, so visitors who merely load the login page are never slowed down:

```nginx
# http context, for example /etc/nginx/conf.d/wp-login-limit.conf
map $request_method $wp_login_key {
    POST    $binary_remote_addr;
    default "";
}
limit_req_zone $wp_login_key zone=wplogin:10m rate=6r/m;
```

```nginx
# inside the site's server block
location = /wp-login.php {
    limit_req zone=wplogin burst=4 nodelay;
    limit_req_status 429;
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/run/php/php8.3-fpm.sock;
}
```

The `map` trick relies on one nginx rule: a request whose key is empty never counts toward the limit. Each address gets six login posts per minute plus a burst of four, which no human needs to exceed. Match the `fastcgi_pass` socket to your PHP version, then run `sudo nginx -t && sudo systemctl reload nginx`.

## WordPress: close XML-RPC if nothing uses it

`xmlrpc.php` is an older remote API that accepts a username and password with every call, and one request can carry many calls. Most sites no longer need it, since the block editor works over the REST API. If no plugin, app or service of yours depends on it (Jetpack and some older publishing tools still can), refuse it at the web server:

```nginx
location = /xmlrpc.php {
    deny all;
}
```

## WordPress: ban with fail2ban

WordPress answers a failed login with status `200` (the form again) and a successful one with a redirect, so failed attempts are easy to spot in the access log. Create `/etc/fail2ban/filter.d/wordpress-login.conf`:

```ini
[Definition]
failregex = ^<HOST> -.*"POST /wp-login\.php HTTP/[0-9.]+" 200
ignoreregex =
```

Then add a jail to `jail.local`:

```ini
[wordpress-login]
enabled = true
port = http,https
filter = wordpress-login
logpath = /var/log/nginx/access.log
maxretry = 5
```

Test the filter against your real log with `sudo fail2ban-regex /var/log/nginx/access.log /etc/fail2ban/filter.d/wordpress-login.conf` before you restart fail2ban. One caution: behind a CDN or reverse proxy, the log records the proxy's address unless nginx is configured to restore the visitor's real IP. Banning the proxy takes the whole site down for everyone.

Inside WordPress, finish the job with long unique passwords, a two-factor plugin for every administrator, and no account named `admin`.

## Hide the login prompts where you can

The strongest protection removes the target. If you manage the server from a few fixed addresses, allow SSH only from them. On CloudSat, a [cloud firewall](https://cloudsat.io/docs/cloud-firewalls) rule for TCP 22 with your addresses in **Sources** drops everything else before it reaches the server. A single-admin WordPress site can do the same for `/wp-login.php` and `/wp-admin/` with nginx `allow` and `deny` lines.

## Check the result a week later

Run the four counting commands from the start of this guide again and compare. `Failed password` lines should disappear once password logins are off, because sshd no longer offers password authentication at all. `Invalid user` lines may continue; they are harmless knocks on a door that has no password lock. fail2ban keeps its own record:

```bash
sudo fail2ban-client status
sudo grep -c ' Ban ' /var/log/fail2ban.log
```

A ban count that keeps climbing is fine: it shows the jails working. A rising number of WordPress login posts that never trigger a ban usually means the filter does not match your log format, so run `fail2ban-regex` again.

## FAQ

### Do I still need fail2ban with key-only SSH?

Not to stop SSH logins from succeeding: with keys only, they cannot. It still trims the logs, saves a little CPU and is worth running for web logins, where passwords remain.

### Can fail2ban lock me out?

Yes, if you mistype your own password enough times. Keep your address in `ignoreip`, keep a second way in such as the provider console, and lift a ban with `fail2ban-client set <jail> unbanip`.

### Does a web application firewall replace these steps?

It adds bot detection and rate rules in front of the site, which helps against large-scale attempts. It does not protect SSH, so the host-level measures stay.

### What about Remote Desktop on Windows servers?

RDP needs an account lockout policy and a firewall scope instead of fail2ban. The steps are in [harden a Windows Server VPS](https://cloudsat.io/learn/harden-a-windows-server-vps).

**Run it on CloudSat.** Cloud VPS on AMD EPYC and NVMe from $1.98/mo in 13 regions, delivered in under 5 minutes and paid in crypto. [See plans](https://cloudsat.io/plans) or [deploy a server](https://dash.cloudsat.io/console/deploy).

## Keep reading

[All guides in Security](https://cloudsat.io/learn/topic/server-security)

- [Linux server hardening: audit what you already run](https://cloudsat.io/learn/linux-server-hardening-audit): Security Linux server hardening: audit what you already run 7 min read
- [Change the SSH port without locking yourself out](https://cloudsat.io/learn/change-ssh-port-safely): Security Change the SSH port without locking yourself out 7 min read
- [Put SafeLine WAF in front of a web app on a Linux VPS](https://cloudsat.io/learn/safeline-waf-reverse-proxy-setup): Security Put SafeLine WAF in front of a web app on a Linux VPS 6 min read
- [SSH host key changed: verify it, then fix the warning](https://cloudsat.io/learn/ssh-host-key-changed-warning-fix): Security SSH host key changed: verify it, then fix the warning 7 min read
