Security 6 min read

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.

By BashPilot Team
BashEdge WAF & DDoS protection Stop Layer 7 floods and malicious requests before they reach the app. Explore BashEdge

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.

which release is this?
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.

is it enabled, and what did it do recently?
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:

does the server need a reboot?
[ -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.

on your own computer
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.

disable passwords and direct root login
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.

a basic web server policy
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.

install it and check the SSH jail
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.

inside your server block
location ~ /\.(?!well-known) {
    deny all;
}
apply it and confirm from outside
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

CheckCommandGood result
Open ports on the serversudo ss -tulpnOnly services you can name
Firewallsudo ufw status verboseActive, default deny incoming
SSH policysudo sshd -Tpasswordauthentication no
Pending rebootls /var/run/reboot-requiredNo such file
Reachable from outsidenc -vz -w 5 SERVER 3306Refused 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.

Share LinkedIn X
Questions

Frequently asked questions

Is UFW enabled by default on Ubuntu Server?

No. Ubuntu's documentation says UFW is initially disabled. Before enabling it on a remote server, allow SSH with `sudo ufw limit 22/tcp` or `sudo ufw allow 22/tcp`, because enabling the firewall can drop existing connections. Check the result with `sudo ufw status verbose`.

Does Ubuntu install security updates automatically?

Yes, in a default install. The `unattended-upgrades` package is installed and applies security updates once a day. It does not reboot by default, so check for `/var/run/reboot-required` regularly. Software from third-party repositories is not included unless you configure it.

Why is password login still working after I set PasswordAuthentication no?

Another file is probably setting it first. SSH uses the first value it reads for each keyword, and files in `/etc/ssh/sshd_config.d/` are read before the main config. Run `sudo sshd -T | grep -i passwordauthentication` to see the effective value, and use a drop-in whose name sorts first, such as `00-hardening.conf`.

Does UFW protect Docker containers?

Not for published ports. Docker routes that traffic before it reaches the chains UFW uses, so a UFW deny rule can appear in the status while the port stays reachable. Bind internal services to localhost with `-p 127.0.0.1:8080:80`, or filter them in Docker's `DOCKER-USER` chain.

Is a firewall enough to secure a web server?

No. A firewall controls which ports and sources can connect, but your web ports must stay open to everyone. Application attacks and request floods arrive through those ports. Keep software patched, protect secrets, and add request-level inspection if the server hosts public applications.

Put your servers on autopilot.

Connect a server in about a minute. The first week is on us.