keepcalculator

06 Numbers and Powers

Protect Your WordPress Site and VPS from Bot Attacks

Card No. 06·72090 · Updated · Standard formula, shown below

This guide walks you through practical steps to harden your WordPress site and its VPS (Virtual Private Server) against automated bot attacks. You’ll learn how to block malicious traffic, reduce spam, and prevent brute-force login attempts, using tools and settings that are available on most hosting setups.

What You’ll Need

  • Administrative access to your WordPress dashboard.
  • SSH (Secure Shell) access to your VPS (root or sudo privileges).
  • Basic familiarity with the command line and file permissions.
  • If you use a control panel like cPanel or Plesk, access to its security features.

Step-by-Step

  1. Update Everything – Start by updating your WordPress core, themes, and plugins to the latest versions. Outdated software is the most common entry point for bots. Also, update your server’s operating system packages (e.g., apt update && apt upgrade on Ubuntu/Debian).
  2. Install a WordPress Security Plugin – Use a reputable security plugin like Wordfence, Sucuri, or Solid Security. These plugins provide firewall rules, login attempt limits, and malware scanning. Configure the plugin to block countries or IP ranges that you don’t need, and enable two-factor authentication (2FA) for admin users.
  3. Change Your Login URL – Bots often target the default /wp-login.php and /wp-admin paths. Rename the login URL using a plugin like WPS Hide Login or by editing your .htaccess file. This alone stops a large portion of automated attacks.
  4. Limit Login Attempts – Set a maximum number of failed login attempts (e.g., 5) before temporarily locking out the IP address. Most security plugins include this feature. For a more aggressive approach, you can add rules to your server’s firewall to ban IPs that exceed a threshold.
  5. Enable CAPTCHA or reCAPTCHA – Add CAPTCHA to your login and registration forms. Google’s reCAPTCHA v3 is invisible to users and works well, but even a simple math CAPTCHA can deter basic bots.
  6. Disable XML-RPC – XML-RPC is often abused for brute-force amplification attacks. Disable it if you don’t use the Jetpack or mobile app features. You can do this via a plugin or by adding a rule to your .htaccess or Nginx config.
  7. Harden Your Server with a Firewall – On your VPS, install a firewall like UFW (Uncomplicated Firewall) for iptables. Only allow necessary ports: 22 (SSH), 80 (HTTP), and 443 (HTTPS). For example, sudo ufw allow 22/tcp, sudo ufw allow 80/tcp, sudo ufw allow 443/tcp, then sudo ufw enable.
  8. Set Up Fail2ban – Fail2ban is a service that monitors logs and bans IPs that show malicious behavior. Install it with sudo apt install fail2ban (or your package manager). Configure it to watch your SSH and web server logs. It automatically adds firewall rules to block repeat offenders.
  9. Protect SSH Access – Disable password authentication for SSH and use SSH keys instead. Edit /etc/ssh/sshd_config and set PasswordAuthentication no. Also, change the default SSH port from 22 to something non-standard (e.g., 2222) to reduce automated scans.
  10. Use a CDN or DDoS Protection – Services like Cloudflare (free tier) can absorb DDoS attacks and filter out malicious bots before they reach your server. Add your site to Cloudflare and set security level to “High” or “I’m Under Attack” during active threats.
  11. Regularly Back Up Your Site – Even with all precautions, a sophisticated attack might succeed. Use a backup plugin or script to create daily off-site backups. Store them on a separate server or cloud storage. Test restoring from backups periodically.

Common Mistakes

  • Blocking all bots – Some bots, like Googlebot, are legitimate. Blocking them can harm your SEO. Use a plugin that distinguishes between good and bad bots.
  • Overly strict firewall rules – Blocking too many IP ranges may lock out legitimate users, especially if you have a global audience.
  • Ignoring security updates – Failing to update WordPress or plugins is the #1 mistake. Bots exploit known vulnerabilities within hours of a patch being released.
  • Not changing default admin username – If your admin user is “admin”, bots have half the credentials already. Create a new admin user with a unique name and delete the old one.
  • Using weak passwords – Even with login limits, a simple password can be cracked. Use a password manager to generate strong, random passwords.

Tips

  • Monitor your logs – Regularly check your server’s access and error logs to spot unusual patterns. Tools like GoAccess can help visualize them.
  • Use a Web Application Firewall (WAF) – Many security plugins include a WAF that filters malicious requests before they reach your site.
  • Enable HTTPS – Use Let’s Encrypt to get a free SSL certificate. HTTPS encrypts data and prevents man-in-the-middle attacks.
  • Disable directory browsing – Prevent bots from listing your files by adding Options -Indexes to your .htaccess or autoindex off; in Nginx.
  • Keep a security checklist – Review your security settings monthly to ensure nothing has been changed or disabled.

Troubleshooting

  • You get locked out of your own site – If you’re locked out due to too many failed attempts, wait for the lockout period to expire, or access your site via FTP and rename the security plugin folder to deactivate it. Then log in and adjust the settings.
  • Legitimate users are blocked – If your firewall or plugin is blocking real users, check the blocked IP list and whitelist any that are false positives. Consider lowering the sensitivity of your bot detection.
  • Site goes down after enabling a security plugin – This may be due to a firewall rule conflicting with your server configuration. Access your site via FTP, rename the plugin folder to deactivate it, and then re-enable it with more conservative settings.
  • Fail2ban bans your own IP – If you accidentally get banned, use the fail2ban-client set sshd unbanip YOUR_IP command to remove the ban. Check your logs to see why it happened and adjust the ignoreip setting.
  • XML-RPC disabled but you need it – If you use Jetpack or the mobile app, you can’t fully disable XML-RPC. Instead, use a plugin that limits XML-RPC requests to your IP or blocks specific methods.

Frequently Asked Questions

Will these steps slow down my site?

Most security measures have minimal impact on performance. A CDN like Cloudflare can actually speed up your site by caching content. The main trade-off is the initial setup time.

Do I need a security plugin if I have a VPS?

Yes. A VPS gives you server-level control, but WordPress itself still needs protection. Security plugins add a layer of defense that server-level tools don’t cover, like file integrity monitoring and login protection.

What is the best way to block bots without affecting SEO?

Use a plugin that maintains a list of known good bots (like Googlebot) and only blocks suspicious ones. Also, avoid blocking entire IP ranges unless they are clearly malicious.

How often should I update WordPress and plugins?

Update as soon as updates are available, especially for security patches. Automate updates for minor releases, and schedule manual updates for major ones after testing on a staging site.

Can I protect my site with just a CDN?

A CDN helps with DDoS and some bot filtering, but it doesn’t protect against brute-force login attempts or plugin vulnerabilities. You still need WordPress-level security.

What should I do if my site is already hacked?

Immediately take your site offline, restore from a clean backup, and then follow this guide to harden it. Also, change all passwords and scan your computer for malware.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →