How to Secure Your VPS: A Practical Checklist
By Harborvm7 min read
Key takeaways
- New internet-facing servers get attacked within hours, so harden SSH before you do anything else.
- Disable password logins and root SSH, then rely on SSH keys and a single sudo user.
- A default-deny firewall plus fail2ban stops most automated brute-force traffic.
- Turn on unattended security updates so patches land without you remembering.
- Harborvm gives you a dedicated vCPU, a private network and WireGuard, but no backups, so keep your own copies.
To secure a VPS, lock down SSH with keys instead of passwords, block root login, put a default-deny firewall in front of it, patch on a schedule, and watch the logs. Do those five things and you shut out almost every automated attack that hits a new server.
This matters because the attacks start fast. Palo Alto's Unit 42 placed 320 exposed honeypots around the world and found that 80% were compromised within 24 hours, and the most-targeted SSH honeypot was hit 169 times in a single day (Unit 42, Exposed Services in Public Clouds). A fresh VPS with a public address is not quietly waiting for you to finish setup. It is already being scanned.
The good news: the defenses are cheap and well understood. Here is the checklist, in the order you should do it.
Harden SSH and disable root login
SSH is the front door, and it is the door attackers knock on most. In AhnLab's honeypot data for the fourth quarter of 2025, a single worm, P2PInfect, accounted for 80.4% of all attacks against Linux SSH servers (AhnLab ASEC). These are automated bots guessing usernames and passwords in a loop.
The fix is to stop accepting passwords at all and to stop letting anyone log in as root.
First, make sure you can get in with a key. If you deployed through Harborvm you can add your SSH public key during setup, so you already have key access before the box is online. If you need a refresher on bringing a server up with your key in place, see how to deploy a VPS from your browser in minutes.
Then edit the SSH config:
sudo nano /etc/ssh/sshd_config
Set these three lines:
PermitRootLogin no
PasswordAuthentication no
PubkeyAuthentication yes
Save, then restart SSH:
sudo systemctl restart ssh
Before you close your current session, open a second terminal and confirm you can still log in with your key. If something is wrong with your key setup, you want to find out while you still have a working session open.
A note on changing the SSH port. Moving off port 22 cuts down noise in your logs, but it is not real security on its own, because a scanner finds the new port in seconds. Treat it as tidying, not defense.

Configure a firewall and fail2ban
A firewall decides which ports are reachable from the internet. The safe default is deny everything, then open only what you need. On Ubuntu and Debian, ufw is the simplest tool:
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow OpenSSH
sudo ufw enable
If you run a web server, add the web ports too:
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
On AlmaLinux, Rocky and Fedora, the equivalent is firewalld with firewall-cmd. The principle is identical: open the few ports your service needs and close the rest.
Firewalls alone do not stop brute-force attempts against the ports you do expose, such as SSH. That is the job of fail2ban. It watches your logs and temporarily bans any IP that fails to log in too many times.
sudo apt install fail2ban
sudo systemctl enable --now fail2ban
Create a local config so upgrades do not overwrite it:
sudo nano /etc/fail2ban/jail.local
A sensible SSH jail looks like this:
[sshd]
enabled = true
maxretry = 5
bantime = 1h
findtime = 10m
That bans an address for an hour after five failed logins in ten minutes. Restart the service to apply it:
sudo systemctl restart fail2ban
Check who is currently banned with sudo fail2ban-client status sshd.
If you want to limit exposure further, Harborvm gives each customer a private network and a built-in WireGuard VPN. You can keep management services, such as a database admin panel, bound to the private network and reach them over WireGuard instead of exposing them to the public internet at all.
Keep packages patched and automate updates
Unpatched software is the other main way servers get taken over. Attackers scan for known flaws and exploit them within hours of a public disclosure, so a patch you apply "next week" is often too late.
Apply updates now:
sudo apt update && sudo apt upgrade
Then stop relying on memory. On Ubuntu and Debian, enable unattended security upgrades:
sudo apt install unattended-upgrades
sudo dpkg-reconfigure --priority=low unattended-upgrades
On AlmaLinux, Rocky and Fedora, dnf-automatic does the same job:
sudo dnf install dnf-automatic
sudo systemctl enable --now dnf-automatic.timer
Automatic updates occasionally require a reboot, for example after a kernel update. Since Harborvm does not offer snapshots or backups, test significant changes carefully and keep your own copy of anything you cannot afford to lose. The update cadence differs between distro families, so pick the base system that matches how often you want to touch the server.
Set up least-privilege users and keys
Running everything as root means one mistake, or one stolen key, hands over the whole machine. Give each person and each service only the access it needs.
Create a normal user and grant sudo:
sudo adduser alice
sudo usermod -aG sudo alice
Add that user's public key:
sudo mkdir -p /home/alice/.ssh
sudo nano /home/alice/.ssh/authorized_keys # paste the public key
sudo chmod 700 /home/alice/.ssh
sudo chmod 600 /home/alice/.ssh/authorized_keys
sudo chown -R alice:alice /home/alice/.ssh
A few habits that keep this tidy:
- Use a separate key per person, never a shared one. When someone leaves, you remove one line from
authorized_keys. - Protect private keys with a passphrase. Credentials are a top way in: in the Verizon 2025 Data Breach Investigations Report, stolen credentials were the most common foothold attackers used.
- Do not reuse your login key for automated jobs. Give scripts and deploy pipelines their own keys with the narrowest access they need.
For services you run, prefer a dedicated system account over root. Most packages create one for you; keep it that way rather than running the daemon as root for convenience.

Monitor for intrusions and suspicious activity
Hardening lowers the odds of a break-in. Monitoring tells you when something slips through anyway.
Start with the basics that are already on the box:
- Read the auth log for failed and successful logins:
sudo journalctl -u sshor/var/log/auth.logon Debian-family systems. - List who is logged in right now with
who, and check recent logins withlast. - Watch listening ports with
sudo ss -tulpn. If a port is open that you did not open, investigate it.
Add a file-integrity and rootkit check for a second layer. Tools such as aide, rkhunter or chkrootkit baseline your system files and flag changes. Run them on a schedule and read the output.
Harborvm also shows live CPU, memory, disk and network graphs for your VPS in the dashboard. A sudden, unexplained spike in outbound network traffic is a classic sign that a server has been roped into a botnet or is mining cryptocurrency for someone else. Knowing your normal baseline makes the abnormal obvious.
Set up a simple alert for the one thing you care about most, usually a jump in outbound traffic or a new user being created, rather than trying to watch everything. An alert you actually read beats a dashboard you never open.
How to secure a VPS, start to finish
Work down the list in order: keys and no root over SSH, a default-deny firewall with fail2ban, automatic patching, least-privilege users, then monitoring. None of it is exotic, and most of it is a one-time setup that keeps paying off.
Your next step is the first one on the list. Open your SSH config today, confirm key login works, and turn off password authentication and root login. If you are provisioning a new box, Harborvm lets you add your SSH key and pick a private network before the VM is even online, so you can start from the hardened end instead of working back to it.
Frequently asked questions
What is the first thing I should do to secure a new VPS?
Create a non-root user with sudo, add your SSH public key, then disable password authentication and root login in the SSH config. That blocks the most common automated attacks on day one.
Do I still need a firewall if I already use fail2ban?
Yes. A firewall decides which ports are reachable at all, while fail2ban bans IPs that fail repeated logins on the services you do expose. They solve different problems and work best together.
How often should I patch my VPS?
Apply security updates as soon as they are available. The simplest approach is to enable automatic security updates so patches install without you remembering to log in.
Does Harborvm back up my VPS for me?
No. Harborvm does not offer backups or snapshots, so you keep your own copies. Export important data to another machine or object storage on a schedule you control.