Skip to contentcloudvix
cloudvix
GuideServers & hosting

VPS security checklist: 12 checks with commands

Denys DunaievskyiFounder, Cloudvix
  • 12 min read
  • Published
  • LevelIntermediate
Guides
On this page

Key takeaways

  • Every check only reads: nothing here changes the server.
  • sshd -T prints the settings the running service really uses, after all configuration files are merged.
  • Docker adds its own firewall rules that run before ufw, so check 4 does not cover published ports.
  • A backup counts when you have restored it somewhere else and opened the result.

Securing a server is not one big step but a list of small ones, and most of them can be checked in seconds. Run each command below on your server and compare the output with what the text says you should see. A check that does not match is a finding to fix, not a reason to panic.

Before you start

The commands assume Ubuntu 24.04 and a user with sudo, as set up in the first-hour guide. Every check only reads: nothing here changes the server. Replace SERVER_IP with the address from the dashboard where a command needs it. If a check fails, the guides linked at the end of the page show how to fix it.

  • an Ubuntu 24.04 server and a login as a user with sudo
  • a terminal on your computer and about ten minutes
  • a note of what this server is meant to run (a web site, a database, apps in Docker), because the right answer to checks 5 and 6 depends on it

The steps

SSH accepts keys only, and not for root

The server must refuse password logins and root logins. sshd -T prints the settings the running service really uses, after all configuration files are merged. Expect permitrootlogin no, passwordauthentication no and pubkeyauthentication yes.

On the serverbash
sudo sshd -T | grep -E 'permitrootlogin|passwordauthentication|pubkeyauthentication'

Only keys you know are allowed

Every line in authorized_keys is a person or a machine that can log in. List the fingerprints and compare them with the keys you remember adding; the comment at the end of each line helps. Check root as well: a missing file is fine. A key you cannot place should be removed.

On the serverbash
ssh-keygen -lf ~/.ssh/authorized_keys
sudo ssh-keygen -lf /root/.ssh/authorized_keys

Nobody has an empty password and only you have sudo

The first command lists the members of the sudo group. The second prints accounts with an empty password: expect no output. The third lists accounts that can log in: expect root, your user and a few system accounts such as sync, and nothing you do not recognise.

On the serverbash
getent group sudo
sudo awk -F: '($2 == "") { print $1 }' /etc/shadow
grep -v -E '(nologin|false)$' /etc/passwd

The firewall is on and denies by default

Expect Status: active, Default: deny (incoming) and rules only for what you chose: OpenSSH, and 80 and 443 if the server runs a web site. Every rule appears twice, once marked (v6) for IPv6.

On the serverbash
sudo ufw status verbose
Warning

Docker publishes ports around ufw. Check 6 covers that.

Only the ports you expect are listening

Read the Local Address column. 127.0.0.1 and [::1] are reachable from the server only; the resolver on 127.0.0.53 is normal. 0.0.0.0, * and [::] mean the whole internet, so only SSH and the services you chose to publish belong there. A database, Redis or an admin panel on 0.0.0.0 is a finding.

On the serverbash
sudo ss -ltnup

Docker publishes only what you meant

Skip this check if Docker is not installed. Docker adds its own firewall rules that run before ufw, so check 4 does not cover published ports. A Ports value that starts with 0.0.0.0 or [::] is open to the internet; 127.0.0.1 is not.

Then look from outside, the way a stranger would. nmap is a separate tool that you install on your own computer. Scan only your own server. Expect the open ports to be exactly the ones you decided on.

On the serverbash
sudo docker ps --format 'table {{.Names}}\t{{.Ports}}'
On your computerbash
nmap -Pn SERVER_IP

Security updates install themselves

Expect both settings to be 1 and the timer to show a next run. Without this, a fix for a known hole waits until you remember to log in.

On the serverbash
apt-config dump | grep -E 'APT::Periodic::(Update-Package-Lists|Unattended-Upgrade)'
systemctl list-timers apt-daily-upgrade.timer

No restart is waiting

After a kernel or library update the new code only runs after a reboot. If the file exists, plan a reboot soon. The automatic-updates guide explains how to choose the time.

On the serverbash
cat /var/run/reboot-required 2>/dev/null || echo "no restart waiting"
uname -r

You can see who is knocking

Every public server is probed all the time, so a count above zero is normal. With key-only login the guesses cannot succeed. What matters are the lines that say Accepted: each must come from an address you know. The last lines show the fail2ban state and only apply if you installed it.

On the serverbash
sudo journalctl -u ssh --since "7 days ago" | grep 'Accepted'
sudo journalctl -u ssh --since "24 hours ago" | grep -c 'Invalid user'
# only if you installed fail2ban:
sudo fail2ban-client status sshd

Secret files can be read by their owner only

The first command finds .env files that other users can read: expect no output. The second finds private keys on the server: expect none, or only ones that you put there on purpose.

On the serverbash
sudo find /home /opt /srv /var/www -name '.env*' -perm /o+r 2>/dev/null
sudo find /home -name 'id_*' -not -name '*.pub' 2>/dev/null
Tip

A private key that lives on a server can be used by anyone who gets into that server.

You have restored a backup, not only made one

No single command can tell you this. A backup counts when you have restored it somewhere else and opened the result. A copy on the same server is lost together with the server. The example uses restic, with RESTIC_REPOSITORY and the password file set first; other tools have the same two steps, list and restore.

On the serverbash
restic snapshots
mkdir -p /tmp/restore-test
restic restore latest --target /tmp/restore-test --include /etc/hostname
diff /tmp/restore-test/etc/hostname /etc/hostname && echo "restore matches"

The clock is right and the disk is not full

Expect NTPSynchronized=yes: a correct clock matters for logs, certificates and one-time codes. Check how much the journal and the disk hold. If the disk is nearly full, find out what fills it before something stops working.

On the serverbash
timedatectl show -p NTPSynchronized
sudo journalctl --disk-usage
df -h /

Check the result

Count your findings. Anything in checks 1, 4, 5, 6 or 10 is urgent: those are open doors. The others are habits such as updates, backups and logs that prevent trouble later. Run the list again after every larger change to the server.

If something goes wrong

sshd -T says passwordauthentication yes

A file that is read earlier is overriding yours. Files in /etc/ssh/sshd_config.d/ are read in name order and the first value of a setting wins, so a name starting with 00 beats the others. After a change run sudo sshd -t and sudo systemctl reload ssh, and keep your session open until a fresh login works.

ss shows a database on 0.0.0.0

Bind it to 127.0.0.1 in its configuration, or publish a Docker port as 127.0.0.1:PORT:PORT. When you need it from your own computer, use an SSH tunnel. Then run check 5 again.

nmap shows a port that ufw status does not list

Almost always Docker, which publishes around ufw. Check 6 shows which container does it.

A check prints nothing at all

For checks 3 (empty passwords) and 10 (readable files) nothing is the good answer. For the others, a missing tool such as fail2ban-client or docker means that tool is not installed, which is not a failure.

Where to go next

After a finding, follow the guide for it: the first-hour guide for SSH and the firewall, the automatic-updates guide for checks 7 and 8, the Docker guide for check 6. Links are at the end of this page. If an assistant built your application, the checklist for AI-built apps covers what lives above the server.

About the author

Denys Dunaievskyi

Founder, Cloudvix

Runs Cloudvix and is responsible for the guides published here.

Related guides

Your server is a few clicks away.

Choose the plan and the system in one order form; the location too, when there is more than one.

Create server