Secure VPS: Prevent Brute Force Attacks in 2025

Protecting your VPS from brute force attacks in 2025 means implementing a multi-layered security strategy that goes beyond just strong passwords. Attackers use automated bots to relentlessly guess login credentials, typically targeting SSH, FTP, and control panel logins. Preventing these attacks is crucial to avoid unauthorized access, data breaches, and service disruption.

Brute force attacks are persistent and automated attempts by attackers to gain unauthorized access to a server by trying countless combinations of usernames and passwords. These attacks primarily target common services like SSH (Secure Shell) for remote server access, FTP (File Transfer Protocol) for file management, and control panel logins (like cPanel/WHM or Plesk). In 2025, these attacks are more sophisticated than ever, demanding proactive and robust defenses.

Securing your Virtual Private Server (VPS) isn’t a one-time task; it’s an ongoing process. This guide outlines essential strategies and tools to protect your VPS from brute force attacks effectively.

1. Harden SSH Access (Your Primary Gateway)

SSH is often the first target for brute force attacks. Securing it is paramount.

1.1 Disable Root Login

Logging in directly as root is a major security risk. Create a new user with sudo privileges and disable direct root login via SSH.

To do this:

  1. Create a new user:Bashsudo adduser your_new_username
  2. Add the new user to the sudo group (or wheel group on CentOS/AlmaLinux):Bashsudo usermod -aG sudo your_new_username # For Ubuntu/Debian # OR sudo usermod -aG wheel your_new_username # For CentOS/AlmaLinux
  3. Switch to the new user and test sudo:Bashsu - your_new_username sudo apt update # Or sudo yum update for AlmaLinux/CentOS
  4. Disable root login in the SSH configuration:Bashsudo nano /etc/ssh/sshd_config Find the line PermitRootLogin yes and change it to:PermitRootLogin no Save and exit (Ctrl+X, Y, Enter).

1.2 Use SSH Key Authentication (Instead of Passwords)

SSH keys are far more secure than passwords because they’re nearly impossible to crack by brute force.

  1. Generate SSH Key Pair: On your local machine (Mac/Linux Terminal or PuTTYgen for Windows):Bashssh-keygen -t ed25519 -b 4096 # Ed25519 is generally preferred for modern systems, but RSA 4096 is also strong. Follow the prompts, creating a strong passphrase for your private key.
  2. Copy Public Key to VPS:Bashssh-copy-id your_new_username@your_vps_ip Enter your new user’s password when prompted.
  3. Disable Password Authentication on VPS:Bashsudo nano /etc/ssh/sshd_config Find PasswordAuthentication yes and change it to:PasswordAuthentication no Find ChallengeResponseAuthentication yes and change it to:ChallengeResponseAuthentication no Save and exit.
  4. Restart SSH Service:Bashsudo systemctl restart sshd Crucial: Before closing your current SSH session, open a new terminal window and try logging in with your SSH key. If it works, you’re good. If not, troubleshoot before closing the old session to avoid being locked out.

1.3 Change Default SSH Port (Port Knocking/Obfuscation)

The default SSH port (22) is constantly scanned. Changing it to a non-standard port (e.g., 2222, 54321) reduces automated scan attempts.

  1. Edit SSH config:Bashsudo nano /etc/ssh/sshd_config Find Port 22 and change 22 to your chosen port:Port 54321 # Example new port Save and exit.
  2. Update your firewall (UFW for Ubuntu/Debian, firewalld for AlmaLinux/CentOS) to allow the new port.
    • UFW:Bashsudo ufw allow 54321/tcp sudo ufw delete allow ssh # Optional: Remove old SSH rule after confirming new one works sudo ufw reload
    • firewalld:Bashsudo firewall-cmd --permanent --add-port=54321/tcp sudo firewall-cmd --reload
  3. Restart SSH service:Bashsudo systemctl restart sshd Remember to specify the new port when connecting via SSH (e.g., ssh -p 54321 your_username@your_vps_ip).

2. Install and Configure Fail2Ban

Fail2Ban is a powerful intrusion prevention framework that scans log files for malicious activity (like repeated failed login attempts) and automatically bans the offending IP addresses using firewall rules.

  1. Install Fail2Ban:
    • Ubuntu/Debian:Bashsudo apt update sudo apt install fail2ban -y
    • AlmaLinux/CentOS:Bashsudo yum install epel-release -y sudo yum install fail2ban -y
  2. Configure Fail2Ban: It’s best practice to create a jail.local file to override default settings and preserve your changes during updates.Bashsudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local sudo nano /etc/fail2ban/jail.local In jail.local, find the [sshd] section and ensure it’s enabled and configured:Ini, TOML[sshd] enabled = true port = ssh,your_new_ssh_port # Make sure to include your new SSH port if you changed it filter = sshd logpath = /var/log/auth.log # or /var/log/secure for AlmaLinux/CentOS maxretry = 3 # Number of failed attempts before ban bantime = 3600 # Ban duration in seconds (1 hour) findtime = 600 # Time window for failed attempts (10 minutes) You can also enable jails for other services like Apache ([apache-auth]), Nginx, FTP ([vsftpd]), or email ([postfix-sasl]) if those services are running on your VPS.
  3. Start and Enable Fail2Ban:Bashsudo systemctl enable fail2ban sudo systemctl start fail2ban To check its status: sudo systemctl status fail2ban or sudo fail2ban-client status.

3. Implement a Strong Firewall

A firewall is your first line of defense, controlling what traffic can reach your VPS.

3.1 Use UFW (Ubuntu/Debian) or firewalld (AlmaLinux/CentOS)

Configure your firewall to only allow necessary ports (e.g., SSH, HTTP, HTTPS) and block all others.

  • UFW (Uncomplicated Firewall):Bashsudo ufw default deny incoming sudo ufw default allow outgoing sudo ufw allow 22/tcp # Default SSH, if not changed sudo ufw allow 54321/tcp # Your new SSH port, if changed sudo ufw allow 80/tcp # HTTP sudo ufw allow 443/tcp # HTTPS sudo ufw enable sudo ufw status verbose
  • firewalld (CentOS/AlmaLinux):Bashsudo systemctl enable --now firewalld sudo firewall-cmd --permanent --add-service=ssh # Uses default 22 # OR, if you changed SSH port: # sudo firewall-cmd --permanent --add-port=54321/tcp sudo firewall-cmd --permanent --add-service=http sudo firewall-cmd --permanent --add-service=https sudo firewall-cmd --reload sudo firewall-cmd --list-all

3.2 Whitelist Trusted IPs

If you have a static IP address for your primary access, you can whitelist it in your firewall to ensure you never get locked out.

  • UFW:Bashsudo ufw allow from your_static_ip to any port 54321 # For your custom SSH port
  • firewalld:Bashsudo firewall-cmd --permanent --zone=public --add-rich-rule='rule family="ipv4" source address="your_static_ip" port port="54321" protocol="tcp" accept' sudo firewall-cmd --reload Replace your_static_ip and 54321 (if applicable).

4. Implement Strong Password Policies & Multi-Factor Authentication (MFA)

Even with SSH keys, other services might still use passwords.

4.1 Use Strong, Unique Passwords

Enforce strong passwords for all user accounts, databases, and services. A strong password includes:

  • Minimum 12-16 characters
  • Mix of uppercase and lowercase letters
  • Numbers
  • Special characters Use a password manager to generate and store these securely.

4.2 Enable Two-Factor Authentication (MFA)

For crucial logins like SSH or control panels (cPanel/WHM, Plesk), enable MFA. This requires a second verification step, usually a code from an authenticator app (like Google Authenticator) or a hardware key.

  • For SSH: You can integrate Google Authenticator with PAM (Pluggable Authentication Modules) on your Linux VPS. This adds a time-based one-time password (TOTP) prompt after your password or SSH key.
  • For Control Panels (e.g., cPanel/WHM): cPanel/WHM has built-in 2FA configuration in its “Security Center” for WHM accounts and “Two-Factor Authentication” in individual cPanel accounts.

5. Regularly Update Your VPS Software

Outdated software is a common entry point for attackers.

  • Operating System: Keep your OS (Ubuntu, AlmaLinux, CentOS) fully updated with the latest security patches.Bashsudo apt update && sudo apt upgrade -y # Ubuntu/Debian sudo yum update -y # AlmaLinux/CentOS
  • Applications: If you’re running a web server (Apache, Nginx), database (MySQL, PostgreSQL), PHP, or a control panel (cPanel), ensure they are always on their latest stable and secure versions. Many control panels offer automated updates for their components.

6. Secure Other Services (FTP, Web Servers, Control Panels)

Brute force attacks aren’t limited to SSH.

6.1 FTP Security

  • Disable FTP if not needed: If you only transfer files via SFTP (SSH File Transfer Protocol), disable your FTP server (e.g., vsftpd).
  • Use SFTP: SFTP is inherently more secure as it runs over SSH.
  • Fail2Ban for FTP: Configure Fail2Ban to monitor FTP login attempts.

6.2 Control Panel Brute Force Protection (e.g., cPHulk)

If you’re using cPanel/WHM:

  • Enable cPHulk Brute Force Protection: This built-in WHM feature protects against brute force attacks on various services including SSH, FTP, Email, and WHM/cPanel logins.
    • Navigate to WHM Home > Security Center > cPHulk Brute Force Protection.
    • Enable it and configure its settings, such as “Username-based Protection” and “IP-based Protection.”
    • Whitelist your IP: Add your static IP address to cPHulk’s whitelist to prevent self-lockout.

6.3 Web Application Firewall (WAF)

For web servers, consider a WAF (like ModSecurity with OWASP CRS or Cloudflare WAF) to filter malicious web traffic, including web-based brute force attacks against login pages (e.g., WordPress login).

Conclusion: A Proactive Defense is Your Best Defense

Securing your VPS from brute force attacks in 2025 requires a proactive, multi-faceted approach. By implementing strong SSH security (SSH keys, disabled root, custom port), deploying Fail2Ban, configuring a robust firewall, enforcing strong password policies with MFA, and keeping all your software updated, you significantly reduce your VPS’s vulnerability. Regular monitoring of logs and adapting to new threats will ensure your server remains a secure and reliable foundation for your online operations. A layered defense is your best strategy against persistent attackers.

Previous Article

10 Reasons Your Startup Needs VPS Now

Next Article

Top 5 AI Tools for Web Hosting Providers in 2025

Subscribe to our Newsletter

Subscribe to our email newsletter to get the latest posts delivered right to your email.
Pure inspiration, zero spam ✨