Hardening Ubuntu 24.04 LTS for Production: The Definitive Security Checklist

A freshly provisioned server receives its first automated scan within minutes of going online. Working through hardening Ubuntu 24 04 LTS for production the definitive security checklist below turns a default install into a host that can sit on the public internet: a non-root admin account, key-only SSH, a default-deny firewall, intrusion prevention, and security patches that apply themselves. It assumes a fresh VPS or dedicated machine, whether that is a budget instance from a comparison like our Hetzner vs DigitalOcean vs OVH roundup or a bare-metal box in a rack.

Hardening Ubuntu 24.04 LTS for Production: The Definitive Security Checklist

Work through the steps in order. Several of them (creating your admin user and copying your SSH key) must happen before the step that disables password login, or you will lock yourself out and be recovering the machine through the provider’s console. Keep your first SSH session open until you have proven a second one can log in.

1. Patch first, then create a non-root admin

Update the package lists and apply pending upgrades before you configure anything, so you are hardening the current version of every daemon rather than last month’s. Then create the account you will actually administer from. Running applications and routine work as root means every bug and every typo lands with full privileges.

sudo apt update && sudo apt upgrade -y

# Create a dedicated administrative user
adduser deployer
usermod -aG sudo deployer

# Verify sudo works before you rely on it
su - deployer -c "sudo whoami"

If you do not have an Ed25519 key pair yet, create one on your own machine first and protect it with a passphrase. The private key never leaves that machine; only the public half goes on the server.

# On your own machine, once
ssh-keygen -t ed25519 -a 100 -f ~/.ssh/id_ed25519

Copy your public key to the new account now, from your own machine, and test it in a fresh terminal while the original session stays open:

ssh-copy-id -i ~/.ssh/id_ed25519.pub deployer@your-server
ssh -p 22 deployer@your-server

2. Harden the SSH daemon

Password authentication is the door every scanner rattles. Disable it, forbid direct root login, and prefer Ed25519 keys. Moving SSH to a non-standard port is optional and is not a security control on its own, but it does cut the volume of automated attempts your logs have to record. Drop a small override file into sshd_config.d rather than editing the main config:

# /etc/ssh/sshd_config.d/99-hardened.conf
Port 22022
PermitRootLogin no
PasswordAuthentication no
PubkeyAuthentication yes
MaxAuthTries 3
ClientAliveInterval 300
ClientAliveCountMax 2
X11Forwarding no

Validate the configuration before restarting anything, and only then reload the daemon:

sudo sshd -t && sudo systemctl restart ssh

If the test login on the new port fails, the session you kept open is your way back in. Fix the config from there instead of reaching for the provider’s rescue mode.

3. Default-deny firewall with UFW

Ubuntu ships with UFW, a friendly front end to the kernel firewall. The policy you want is simple: refuse everything inbound that you did not explicitly ask for, allow outbound traffic, and open only SSH and the web ports your services need. Allow the SSH port before enabling the firewall, in the same session, so the enable step cannot cut you off.

ufw default deny incoming
ufw default allow outgoing

ufw allow 22022/tcp comment "Hardened SSH"
ufw allow 80/tcp comment "HTTP"
ufw allow 443/tcp comment "HTTPS"

ufw enable
ufw status verbose

One refinement worth knowing: ufw limit 22022/tcp rate-limits new connections to a port instead of simply allowing them, which blunts connection floods at the firewall layer. It is optional here because key-only authentication already removes the password-guessing risk, but on a port that still accepts passwords it earns its place.

4. Intrusion prevention with Fail2ban

Key-only login stops attackers from guessing passwords, but connection floods still consume sockets and fill logs. Fail2ban watches the authentication log and temporarily bans addresses that fail repeatedly. Copy the stock config to a local override, then define your SSH jail with the port you chose in step 2:

sudo apt install -y fail2ban
sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
# /etc/fail2ban/jail.d/sshd.local
[sshd]
enabled = true
port = 22022
filter = sshd
maxretry = 3
findtime = 600
bantime = 86400

Restart the service and confirm the jail is active with sudo fail2ban-client status sshd. The bans are a speed bump, not a wall; their job is to keep log noise and connection churn down so real anomalies stay visible.

5. Automatic security updates

Most compromised servers were not beaten by a zero-day. They were beaten by a known vulnerability with a published fix that nobody applied. Ubuntu’s unattended-upgrades package closes that gap for security updates. Install it, then make sure the periodic schedule is switched on:

sudo apt install -y unattended-upgrades
sudo dpkg-reconfigure --priority=low unattended-upgrades
# /etc/apt/apt.conf.d/20auto-upgrades
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "1";

Leave automatic reboot off unless the server can tolerate it. Kernel updates that need a restart will wait for your maintenance window, and /var/run/reboot-required tells you when one is pending. Knowing a reboot is owed beats being surprised by one.

6. Shrink the attack surface

Every listening service is a door you have to keep patched. List what is actually listening, then disable what the machine does not need:

# What is listening right now?
sudo ss -tulpn

# Example: stop and disable a service you do not use
sudo systemctl disable --now cups

Ubuntu enables AppArmor by default, which confines applications to defined profiles; check it is running with sudo aa-status rather than assuming. A handful of conservative network settings in /etc/sysctl.d/99-hardening.conf are also standard practice:

# Ignore ICMP broadcast requests and bogus error responses
net.ipv4.icmp_echo_ignore_broadcasts = 1
net.ipv4.icmp_ignore_bogus_error_responses = 1
# Reverse-path filtering against spoofed source addresses
net.ipv4.conf.all.rp_filter = 1
net.ipv4.conf.default.rp_filter = 1
# Log packets with impossible source addresses
net.ipv4.conf.all.log_martians = 1

Apply them with sudo sysctl --system and re-check your application still behaves, because aggressive sysctl tuning can break containers and VPNs that depend on looser network behaviour.

Which defensive layer does what

These tools are complements, not rivals. The overlap confuses people into installing all three badly instead of one or two well.

Tool Layer Overhead Best for
UFW Network and port filtering Negligible Every server, as the baseline
Fail2ban Log-based reactive bans Low Cutting SSH and login-attempt noise
CrowdSec Shared threat intelligence plus local detection Moderate Fleets that benefit from pooled blocklists

7. Audit on a schedule, and automate the baseline

Hardening decays: someone opens a port for a test, a service gets installed, an update changes a default. A periodic audit catches the drift. Lynis is the standard open-source auditor for this; run it after your initial setup to record a baseline, then again whenever the machine changes role. Reviewing authentication logs with journalctl -u ssh once in a while is the manual version of the same habit. Extend the audit to people as well as software: list the accounts that can log in, check who holds sudo rights, and remove both when a contractor or a former teammate no longer needs them. Leftover access is the quietest hole in an otherwise careful setup, because nothing about it looks like an attack.

sudo apt install -y lynis
sudo lynis audit system

Once one machine is right, codify the result instead of repeating the clicks per server. Expressing the same baseline as infrastructure as code with Terraform or Pulumi makes the setup reviewable and repeatable, and teams that manage configuration as code often pair it with a GitOps workflow such as ArgoCD for the workloads on top. Configuration management is table stakes in cloud and devops work for exactly this reason: the checklist stops depending on anyone’s memory.

Keep a way back in

Before you call the job done, prove your recovery paths while you do not need them. Log in through the provider’s web console once, so you know it works if SSH ever breaks. Take a snapshot or image backup of the hardened machine before applications move in, because restoring a known-good image is faster than rebuilding this checklist from notes under pressure. Store the snapshot somewhere other than the server itself. These steps feel like overhead on setup day and like foresight on the one day a bad config, a failed upgrade, or a lost laptop with your only key on it would otherwise end the story.

The checklist, condensed

Print this page and you have the hardening Ubuntu 24 04 LTS production definitive security checklist in one list: patch the system; create a non-root sudo user; copy your Ed25519 key and test it; disable password and root SSH login; set UFW to default-deny and open only the ports you use; enable Fail2ban on the SSH jail; turn on unattended security upgrades; remove or disable every service that does not need to listen; confirm AppArmor is active; and schedule a recurring audit. None of these steps is exotic. Together they move a default install out of the path of the automated scanning that makes up most attacks, and they leave you a server whose security state you can describe in one paragraph, which is the real goal.

Ditulis oleh

Firdaus Safari Putra

Founder, PT FirKaizen Digital Solutions

Firdaus Safari Putra adalah founder PT FirKaizen Digital Solutions. Ia membangun dan mengoperasikan infrastruktur server di balik panduan ini, dan menulis berdasarkan apa yang benar-benar ia jalankan, uji, dan ukur — bukan teori.