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.
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.
ssh-keygen -lf ~/.ssh/authorized_keys
sudo ssh-keygen -lf /root/.ssh/authorized_keysNobody 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.
getent group sudo
sudo awk -F: '($2 == "") { print $1 }' /etc/shadow
grep -v -E '(nologin|false)$' /etc/passwdThe 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.
sudo ufw status verboseDocker 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.
sudo ss -ltnupDocker 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.
sudo docker ps --format 'table {{.Names}}\t{{.Ports}}'nmap -Pn SERVER_IPSecurity 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.
apt-config dump | grep -E 'APT::Periodic::(Update-Package-Lists|Unattended-Upgrade)'
systemctl list-timers apt-daily-upgrade.timerNo 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.
cat /var/run/reboot-required 2>/dev/null || echo "no restart waiting"
uname -rYou 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.
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 sshdSecret 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.
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/nullA 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.
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.
timedatectl show -p NTPSynchronized
sudo journalctl --disk-usage
df -h /Let an assistant run the checks, read-only
The prompt below makes an assistant run the same twelve checks and report. It is told to change nothing and to show you the commands first. Give it a key that you can remove afterwards, not your main key: while it is connected it has the same power as the user it logs in as.
Read the commands before you answer yes. If you then let the assistant fix a finding, do it one finding at a time, again with a plan first.
You are auditing an Ubuntu 24.04 server at SERVER_IP. Connect over SSH as the user ops, which has sudo.
Rules:
1. Read-only. Do not install, change, restart or delete anything.
2. Before you start, show me a numbered list of the commands you will run and wait for my yes.
3. For each of these areas run the check and report OK, a finding or not applicable, with the output as evidence: SSH settings; authorized keys; users, the sudo group and empty passwords; ufw; listening ports; ports published by Docker; automatic updates; a pending reboot; accepted and failed SSH logins; .env files others can read and private keys on the server; backups (ask me how I restore them, do not guess); clock and disk.
4. Never print the contents of a secret file, a private key or a password. Show names, permissions and counts only.
At the end give a table: area, result, what I should fix first.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.
Runs Cloudvix and is responsible for the guides published here.