Back to articles
Cloud VPS HostingAvertHostNovember 25, 20269 min read

VPS Security Checklist: Harden and Audit a Linux VPS

A practical VPS security checklist for Ubuntu: audit open ports, SSH, firewall, patching, accounts, logs and backups, plus what to document for DPDP.

VPS security means reducing what an attacker can reach, limiting what a compromised account can do, and being able to see and recover from an incident. On a Linux VPS that comes down to key-only SSH, a default-deny firewall, patched software, least-privilege accounts, logs you actually read, and tested backups. This guide goes beyond initial setup: it shows how to audit a server you already run, with commands you can paste on Ubuntu 22.04 or 24.04.

If the server is brand new, start with the first 30 minutes of VPS setup, which covers the initial hardening steps. This article assumes that is done and asks the harder question: how do you know it is still true?

Know your exposure: what is listening on the server

You cannot protect a port you do not know is open. Start from the outside view, then compare it with the inside view.

sudo ss -tulpn
sudo ufw status verbose

The first command lists every listening TCP and UDP socket with the owning process. Anything bound to 0.0.0.0 or [::] is reachable from the internet unless the firewall blocks it. Anything bound to 127.0.0.1 is local only.

Typical findings:

  • Databases on a public address. MySQL, PostgreSQL, Redis and MongoDB should listen on 127.0.0.1 or a private address, never on the public interface.
  • Admin panels and dev servers left running on a high port after a test.
  • Container ports published by Docker, which can bypass ufw rules (see the Docker VPS guide for the fix).

Then scan from a different machine, such as your laptop, to confirm what the internet sees: nmap -Pn -p- your.server.ip. Scan only servers you own. The two lists should match: every open port should have a reason you can state in one sentence.

SSH: keys only, few users, no root

SSH is the main door into a Linux VPS, and automated scanners try it within minutes of a server going online. Check the effective configuration rather than the file you remember editing:

sudo sshd -T | grep -E 'permitrootlogin|passwordauthentication|pubkeyauthentication|maxauthtries|allowusers'

You want permitrootlogin no, passwordauthentication no and pubkeyauthentication yes. Put overrides in /etc/ssh/sshd_config.d/50-hardening.conf so package upgrades do not overwrite them, and restrict who may log in:

PermitRootLogin no
PasswordAuthentication no
MaxAuthTries 3
AllowUsers deploy alice

Test with sudo sshd -t and keep your current session open while you open a second one to confirm the login still works. Then audit the keys themselves:

  • Read ~/.ssh/authorized_keys for every user. Remove keys of people who have left, and keys you cannot identify. Put a comment with the person and date on each key.
  • Use one key per person and per laptop. Shared keys mean you cannot tell who did what.
  • Prefer Ed25519 keys protected by a passphrase: ssh-keygen -t ed25519.

Moving SSH to another port reduces log noise but is not a security control. Do it if you like, but rely on keys and the firewall.

Firewall: default deny, then allow what you can name

Two firewalls matter: the one on the server and, if your provider offers one, a network-level firewall in front of it. On Ubuntu, ufw is a simple front end for the kernel firewall:

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

ufw limit rate-limits repeated SSH connection attempts. If you have a fixed office or VPN address, go further and allow SSH only from it: sudo ufw allow from 203.0.113.10 to any port 22 proto tcp (replace the documentation address with yours). For a Windows server the equivalent is restricting RDP, covered in how to secure RDP on a Windows VPS.

Review the rule list quarterly. Rules added "temporarily" for a vendor or a test are the most common source of forgotten exposure. See the Ubuntu firewall documentation for the full syntax.

Patching: automatic security updates and a reboot plan

Most real-world compromises use vulnerabilities that already have a fix. Enable unattended security updates and check that they really run:

sudo apt install unattended-upgrades
sudo dpkg-reconfigure -plow unattended-upgrades
sudo unattended-upgrade --dry-run --debug | tail -20
ls /var/run/reboot-required 2>/dev/null

Kernel and libc updates only take effect after a reboot, so schedule a monthly maintenance window. Also track software that apt does not manage: Docker images, Node and Python dependencies, WordPress plugins and anything installed from a script. List what is outdated with apt list --upgradable and docker images, and set a calendar reminder to rebuild images. The monthly Linux VPS management checklist gives a routine for this.

Accounts and privileges: least privilege in practice

Run each application under its own unprivileged user, not as root and not as your admin user. Then audit who can do what:

getent group sudo
sudo awk -F: '($2==""){print $1}' /etc/shadow
sudo lastlog | grep -v 'Never logged in'
sudo find / -xdev -perm -4000 -type f 2>/dev/null
  • Sudo group: everyone listed should be someone you can name. Remove ex-staff accounts with sudo deluser --remove-home name or lock them with sudo usermod -L -e 1 name.
  • Empty passwords: the awk command prints accounts with a blank password hash; there should be none.
  • Last logins: an account that never should log in but did is a red flag.
  • SUID binaries: compare the list with a clean install of the same version; unknown entries deserve investigation.

Application secrets belong in files readable only by the service user (chmod 600) or in your deployment tool's secret store, never in a git repository. If a secret has been committed or pasted into a chat, rotate it.

Stop brute force and watch the logs

fail2ban reads logs and temporarily blocks addresses that repeatedly fail authentication. A minimal SSH jail goes in /etc/fail2ban/jail.local:

[sshd]
enabled = true
maxretry = 5
findtime = 10m
bantime = 1h

Check it with sudo fail2ban-client status sshd. Treat it as noise reduction. It does not replace key-only login, because a distributed attack uses many addresses.

Then read the logs on purpose. Four commands cover most of what a small team needs weekly:

sudo journalctl -u ssh --since "7 days ago" | grep -i accepted
sudo journalctl -p err --since yesterday
sudo last -n 20
sudo grep -c "Failed password" /var/log/auth.log

"Accepted" lines show successful logins: check the user and source address against what you expect. A login from an unfamiliar country or at an odd hour deserves a question to the account owner. For stronger detection, enable the kernel audit framework (auditd) with rules for changes to /etc/passwd, /etc/sudoers and SSH config, and send logs to a second place, because an attacker with root can edit local logs.

Add a second factor for interactive logins

Keys protect against password guessing, but a stolen laptop with an unlocked key is still a risk. Two practical options:

  • Passphrase-protected keys plus disk encryption on every admin laptop. This is free and covers the lost-device case.
  • TOTP through PAM (the libpam-google-authenticator package) so SSH requires both the key and a one-time code. Configure it carefully and keep a break-glass session open while testing, or you can lock yourself out.

Also enable two-factor authentication on the control panel where you manage the VPS, your domain registrar and your email, since those accounts can reset everything else.

Backups and recovery are part of security

Ransomware, a bad deployment and a deleted volume all end the same way: you need a clean copy. Keep at least one backup that the server itself cannot delete or overwrite, and test a restore. The full method is in cloud server backup: snapshots, offsite copies and restore tests. Write down, in a short runbook, who can rebuild the server, where the backups are and how long you expect recovery to take.

Security and DPDP: what to document

If your server stores personal data of people in India, the Digital Personal Data Protection Act expects "reasonable security safeguards". The law does not give a command list, so the practical step is evidence: a record of what you do. Keep a one-page document showing who has admin access, how access is removed when staff leave, how often patches are applied, where backups are and where the data is physically stored. Read the official text via the MeitY data protection framework page, and see why Indian businesses are moving hosting back to India for the data location side. This is operational guidance, not legal advice; ask your counsel about obligations specific to your business.

A quarterly VPS security audit checklist

  1. Compare ss -tulpn and an external nmap scan with your list of intended ports.
  2. Run sshd -T and confirm no root login and no password login.
  3. Review authorized_keys for every user and remove stale keys.
  4. Review the sudo group and local accounts against current staff.
  5. Confirm unattended upgrades ran and apply any pending reboot.
  6. Check fail2ban status and the last 7 days of accepted logins.
  7. Restore one backup to a test server and time it.
  8. Rotate any secret that left the team with a person or appeared in a repository.
  9. Update the one-page access and safeguards record.

How AvertHost can help

AvertHost provides Linux cloud VPS and Windows cloud VPS hosted in a Tier-IV data centre in Delhi, backed by a 99.9% uptime SLA, with INR billing and GST invoices. Because the servers are in India, the data location part of a DPDP review is straightforward to document. The firewall and OS-level settings described here are your own configuration, so the audit above is yours to run; the services page lists the other options.

FAQ

What is the single most important VPS security step?

Disable password login for SSH and use keys, together with a default-deny firewall. Those two steps remove the most common attack path, which is password guessing against an exposed port.

Do I need fail2ban if I use SSH keys?

It is not essential, but it cuts log noise and slows scanners. It is a convenience layer, not a replacement for key-only authentication.

How often should I audit my VPS?

Run a quick check of open ports and recent logins weekly, and the full checklist above quarterly or after any staff change. Apply security patches continuously through unattended upgrades.

Is a Linux VPS secure by default?

No. A fresh image is a starting point: it usually has a reachable SSH service and no tuned firewall rules. Security comes from your configuration and ongoing maintenance.

Does moving SSH to a different port make it secure?

It reduces automated noise but does not stop a targeted attacker, who can scan all ports. Treat it as optional and rely on keys, the firewall and updates.