Ubuntu Server Security Checklist for Web Servers
No checklist makes a server unbreakable, but a short list done in the right order removes most of what automated attacks rely on.
Ubuntu server security on a public web host comes down to a short list of jobs done in a sensible order. Bots start probing a new IP address almost as soon as it comes online, looking for password logins, exposed .env files and software that missed a patch. This checklist covers what to change on Ubuntu 22.04, 24.04 or 26.04, and how to prove each change took effect, because a setting you never verified is only a hope.
1. Know your support window
No hardening makes up for a release that has stopped receiving fixes. According to Ubuntu's release cycle, standard security maintenance runs to May 2027 for 22.04 LTS, May 2029 for 24.04 LTS and May 2031 for 26.04 LTS. Ubuntu Pro extends those dates, and is free for personal use on up to five machines.
lsb_release -a
2. Confirm patches are really being applied
Ubuntu installs unattended-upgrades by default and applies security updates once a day. Servers built from custom images sometimes have it switched off, so look instead of assuming.
cat /etc/apt/apt.conf.d/20auto-upgrades
sudo unattended-upgrade -v --dry-run
sudo tail -n 20 /var/log/unattended-upgrades/unattended-upgrades.log
Both values in 20auto-upgrades should be "1". A 0 disables that action. Packages from third-party repositories are a common blind spot, since adding a repository does not make unattended-upgrades consider it. If you installed PHP, nginx or MariaDB from an outside repo, patch those on a schedule of your own.
The default for Unattended-Upgrade::Automatic-Reboot is false, which is reasonable on a production server but leaves new kernels unused until someone restarts it. Add this file to your weekly routine:
[ -f /var/run/reboot-required ] && cat /var/run/reboot-required.pkgs
3. Move SSH to keys
Password guessing is the noise in every SSH log. Key-only login makes it irrelevant. Create a key on your own computer and copy it to the server, then log in with it in a new terminal before you change anything.
ssh-keygen -t ed25519
ssh-copy-id deploy@203.0.113.10
ssh deploy@203.0.113.10
Now add a small drop-in file. The filename matters more than you would expect. The sshd_config manual says the first value obtained for a keyword is the one used, and drop-ins are read in name order at the start of the configuration. Cloud images often include their own file that turns password login back on, so a name starting with 00- makes sure yours is read first.
printf 'PasswordAuthentication no\nKbdInteractiveAuthentication no\nPermitRootLogin no\n' | sudo tee /etc/ssh/sshd_config.d/00-hardening.conf
sudo sshd -t
sudo sshd -T | grep -Ei '^(passwordauthentication|kbdinteractiveauthentication|permitrootlogin)'
sudo systemctl restart ssh
4. Turn on UFW in the right order
UFW is installed but initially disabled. The rule that protects you from yourself is the first one: allow SSH before you enable anything. The limit rule is a good fit here, because it denies an address that opens 6 or more connections within 30 seconds.
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw limit 22/tcp
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw show added
sudo ufw enable
sudo ufw status verbose
If you use automation that opens several SSH connections quickly, such as a deployment tool, use ufw allow from YOUR_IP to any port 22 proto tcp for that address, or limit will start refusing it.
5. Slow down repeated logins with Fail2Ban
With SSH on keys, Fail2Ban is mainly about cutting log noise. It earns more on services that still use passwords, such as mail logins and web admin panels. Add your own address to ignoreip in /etc/fail2ban/jail.local first so a typo cannot ban you.
sudo apt install fail2ban
sudo systemctl enable --now fail2ban
sudo fail2ban-client status sshd
6. Check that AppArmor is enforcing
Ubuntu loads AppArmor by default. It limits what a confined program can touch if it gets compromised. Run sudo aa-status and look at how many profiles are in enforce mode, and be wary of anyone whose fix for a permission error was to disable it.
7. Stop serving what should never be public
Scanners ask every site for /.env, /.git/config and database dumps. One leaked .env can hand over database and API credentials without any exploit at all. In nginx, deny hidden files while leaving the path certificate renewals depend on.
location ~ /\.(?!well-known) {
deny all;
}
sudo nginx -t && sudo systemctl reload nginx
curl -s -o /dev/null -w '%{http_code}\n' https://example.com/.env
curl -s -o /dev/null -w '%{http_code}\n' https://example.com/.git/config
You want 403 or 404 from both. A 200 means the file is being served, and the credentials inside it should be treated as stolen and rotated. The exception for .well-known matters: without it, Certbot renewal can fail a few weeks later and nobody will connect the two.
8. Do a final outside-in review
| Check | Command | Good result |
|---|---|---|
| Open ports on the server | sudo ss -tulpn | Only services you can name |
| Firewall | sudo ufw status verbose | Active, default deny incoming |
| SSH policy | sudo sshd -T | passwordauthentication no |
| Pending reboot | ls /var/run/reboot-required | No such file |
| Reachable from outside | nc -vz -w 5 SERVER 3306 | Refused or timed out |
Where this checklist stops
Everything above reduces what an attacker can reach. It does not inspect what comes through the ports you left open on purpose. A valid-looking request to 443 can carry an injection, and thousands of them can exhaust PHP workers, which is the gap covered in WAF vs Firewall: Which One Stops Layer 7 DDoS Attacks?. BashEdge for Ubuntu works alongside UFW and Fail2Ban and leaves existing rules in place. It adds more than 50 maintained web attack rules plus request-flood protection for nginx and Apache, and starts in monitor mode so you can review its decisions first.