Blueprints · Server Hardening
Production
15 min · Fail2Ban
Fail2Ban jails for SSH, Nginx, and WordPress
Enables sshd, nginx-http-auth, nginx-botsearch, and a WordPress login jail. Ban time increments. Your admin address is ignored.
Live config
Baked-in protections
- sshd, nginx auth, nginx bot search, and WordPress login are jailed
- bantime.increment is true
- The admin CIDR is on ignoreip
- The SSH jail follows SSH_PORT
Step 1 · ini
Jail config
/etc/fail2ban/jail.d/portgate.local
The WordPress filter matches POST /wp-login.php that returned 200, which is the usual failed-login pattern when the theme still returns 200. Tune it to your access log.
[DEFAULT] bantime = 1h bantime.increment = true findtime = 10m maxretry = 5 ignoreip = 127.0.0.1/8 ::1 203.0.113.10/32 [sshd] enabled = true port = 22 [nginx-http-auth] enabled = true [nginx-botsearch] enabled = true [wordpress-auth] enabled = true port = http,https filter = wordpress-auth logpath = /var/log/nginx/access.log maxretry = 5
Step 2 · bash
WordPress filter and reload
/root/portgate-blueprints/fail2ban-apply.sh
Installs the package when apt or dnf is available, then reloads Fail2Ban.
#!/bin/sh set -eu if command -v apt-get >/dev/null 2>&1; then apt-get update apt-get install -y fail2ban elif command -v dnf >/dev/null 2>&1; then dnf install -y fail2ban else echo "Install fail2ban, then copy the jail file." exit 0 fi cat > /etc/fail2ban/filter.d/wordpress-auth.conf <<'EOF' [Definition] failregex = ^<HOST> -.*POST /wp-login\.php ignoreregex = EOF systemctl enable --now fail2ban systemctl reload fail2ban || systemctl restart fail2ban