How to Secure a Linux VPS from Brute Force Attacks: A 30-Minute Checklist for Beginners

By Diq - Editor & Writer at The Tips Tricks Technology 6 min read 13 views
How to Secure a Linux VPS from Brute Force Attacks: A 30-Minute Checklist for Beginners
Illustration: How to Secure a Linux VPS from Brute Force Attacks: A 30-Minute Checklist for Beginners
Table of Contents
  1. Quick 5-Minute Check: Early Detection of Brute Force Attacks
  2. Step-by-Step Security Hardening: From Easy to Critical
  3. Signs You Must Call a Technician/Server Admin
  4. Comparison of Authentication Methods and Their Impact
  5. Prevention and Monitoring Habits

You've just spun up a Linux VPS and connected it to the internet. Within minutes, the authentication log file (/var/log/auth.log) starts filling up with hundreds of failed login attempts from various foreign IPs. If left unchecked, not only is administrator access at risk, but the server's CPU and memory get drained as the SSH service stays busy processing fake requests. These brute force attacks are often underestimated because the symptoms aren't immediately visible, but the impact can be severe: a slow server, lost access, or leaked data.

Why does a new VPS immediately become a target? Automated botnets on the internet scan the entire public IPv4 range looking for open port 22. This port is the standard SSH entry point on nearly every Linux distribution. Three default gaps are most commonly exploited: the root account is allowed to log in directly from the public network, authentication still uses plain passwords, and there's no mechanism to limit failed attempts. Closing these gaps from day one will drastically cut your risk.

Quick 5-Minute Check: Early Detection of Brute Force Attacks

Before diving into configuration, do a quick inspection to find out whether your server is under attack. Open an SSH terminal and run the following command:

sudo journalctl -u ssh --since "5 minutes ago" | grep -i "failed" | wc -l

If the result is more than 10 within 5 minutes, your server is being targeted. You can also check the list of IPs that most frequently fail to log in:

sudo journalctl -u ssh --since "1 hour ago" | grep -i "failed" | grep -oE "[0-9]+.[0-9]+.[0-9]+.[0-9]+" | sort | uniq -c | sort -nr | head

Other symptoms you might notice: SSH connections feel slow, a "Too many authentication failures" message appears, or you suddenly get disconnected. If you spot these signs, proceed immediately to the security steps below.

Step-by-Step Security Hardening: From Easy to Critical

Follow this order according to urgency. Each step includes an estimated time and cost range (if any).

1. Update the System and Security Packages (2 minutes, free)

Make sure your operating system has the latest security patches so that old vulnerabilities in the SSH daemon or system libraries are closed.

sudo apt update && sudo apt upgrade -y

For RHEL-based distributions, use sudo dnf update -y.

2. Create a New User Account with Sudo Access (3 minutes, free)

Performing daily administration with a non-root account prevents attackers from knowing your main account name. Create a new user with a name that's hard to guess.

adduser adminserver
usermod -aG sudo adminserver

Test the new account by opening a separate terminal window and logging in with the new username before continuing.

3. Implement SSH Key Authentication (5 minutes, free)

SSH cryptographic keys are far more secure than passwords because they're nearly impossible to guess. Generate the key pair on your local computer, not on the server.

ssh-keygen -t ed25519 -C "main-vps-access"

Copy the public key to the new user account on the server:

ssh-copy-id adminserver@YOUR_SERVER_IP

Try logging in again. If you get in without being prompted for the server account password, SSH key authentication is working.

4. Tighten the SSH Configuration (5 minutes, free)

This is the most critical stage: disable root login, turn off password authentication, and move the SSH port from 22 to another number above 1024.

sudo nano /etc/ssh/sshd_config

Change the following lines (remove the hash sign if they're still commented out):

Port 2244
PermitRootLogin no
PasswordAuthentication no
PubkeyAuthentication yes
MaxAuthTries 3

Save, then check the syntax and restart the service:

sudo sshd -t
sudo systemctl restart ssh

Field Note: Never close your first SSH terminal session before you've successfully logged in on a new terminal window using the new port and SSH key. If a firewall or configuration mistake happens, the first session is your lifeline so you don't get locked out of your own server.

Note: If UFW is already active, run sudo ufw allow 2244/tcp first before restarting SSH. If you're using a cloud provider's firewall such as AWS, Google Cloud, or DigitalOcean, also open port 2244 in the cloud's Security Group / Firewall, not just in UFW.

5. Enable the UFW Firewall (3 minutes, free)

A firewall ensures only the ports you need are accessible from outside. Allow the new SSH port first before enabling the firewall.

sudo ufw allow 2244/tcp
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw enable

Check the active rules with sudo ufw status verbose.

6. Install and Configure Fail2Ban (5 minutes, free)

Fail2Ban monitors the authentication log in real-time. If a single IP fails to log in repeatedly beyond the limit, Fail2Ban automatically blocks that IP through the firewall for a set duration.

sudo apt install fail2ban -y
sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
sudo nano /etc/fail2ban/jail.local

In the [sshd] section, adjust the following parameters to match your new SSH port:

[sshd]
enabled = true
port = 2244
maxretry = 3
findtime = 10m
bantime = 1h

Enable the service and verify the blocking status:

sudo systemctl enable --now fail2ban
sudo fail2ban-client status sshd

Signs You Must Call a Technician/Server Admin

If you find the following indications, seek expert help immediately:

  • There's a suspicious process running as root (check with ps aux | grep root).
  • Log files suddenly disappear or their permissions change.
  • Outbound connections appear to foreign IPs you don't recognize (use ss -tunap).
  • The server sends mass emails without your knowledge (a sign of spam).

In cases like these, the best step is to isolate the server (temporarily disable the network) and perform a forensic audit.

Comparison of Authentication Methods and Their Impact

MethodEase of GuessingBrute Force RiskConvenience
Simple passwordHighVery highEasy, but insecure
Complex passwordMediumHigh (if unthrottled)Fairly easy
SSH Key (no passphrase)Very lowVery lowConvenient, but the key must be protected
SSH Key + passphraseVery lowVery lowSecure, slightly more hassle at login

From the table above, the combination of SSH key and passphrase is the most recommended. If you manage many servers, store your list of SSH keys and their passphrases in an encrypted password manager, not in a plain text file.

Prevention and Monitoring Habits

Server security isn't a one-time job. Get into the habit of checking the authentication log regularly:

sudo journalctl -u ssh -n 50

Enable automatic security updates with unattended-upgrades so critical patches are always applied. Add a passphrase to your SSH private key and keep a backup in a safe place. If the VPS runs a database like MySQL, make sure it only listens for local connections on 127.0.0.1.

To monitor network traffic in real-time, use iftop or nethogs. Use a combination of firewall + Fail2Ban + SSH key as layered defense.

If you manage a website on the VPS, also make sure you understand how to force HTTPS via .htaccess and its alternatives to secure your visitors' connections.

The most recommended first step today: open a terminal, run sudo journalctl -u ssh --since "5 minutes ago" | grep -i "failed" | wc -l. If the number is more than 10, immediately implement SSH keys and disable password authentication. Don't put it off until tomorrow, because every minute without protection means an open door for curious bots.

Share:
D
About the Author
Diq Editor & Writer at The Tips Tricks

IT practitioner and web developer. Writes practical, hands-on technology guides covering the web, software, everyday devices, and internet troubleshooting in clear, actionable steps.

About & Editorial →

Discussion (0)

No comments yet. Be the first to join the discussion.