Ubuntu 24.04 Server Setup Checklist for Production Apps
Practical Ubuntu 24.04 server setup checklist: SSH hardening, UFW firewall, swap, unattended upgrades, UTC time, journald limits, and database isolation.
· 7 min read
On this page
If you spin up a brand-new Ubuntu VPS on Hetzner, DigitalOcean, or Vultr and watch journalctl -u ssh -f, it takes roughly 90 seconds before automated scanners start hammering port 22 with root, admin, and ubuntu password guesses.
Hardening a Linux server isn't about paranoia or turning your weekend into a 200-page compliance audit. It's about knocking out the ten high-leverage defaults that prevent 99% of real-world compromises and midnight outages — things like passwordless SSH-only auth, catching Ubuntu 24.04's sneaky 50-cloud-init.conf override, least-privilege deploy users, localhost-only databases, swap so the OOM killer doesn't murder PostgreSQL during a Composer install, and capping journald so logs never silently fill a 20 GB disk.
This Ubuntu 24.04 server setup checklist is the exact routine I run on every production Ubuntu 24.04 LTS (and 26.04 LTS) box before a single line of application code lands on it. Every command below is copy-pasteable, safe to run twice, and explains why it matters in production.
1. Patch the Base Image and Turn On Unattended Security Upgrades
Cloud VPS images are often weeks behind on kernel, OpenSSL, and OpenSSH patches. Update immediately and enable automatic security-only updates:
sudo apt-get update && sudo apt-get upgrade -y
sudo apt-get install -y unattended-upgrades apt-listchanges
sudo dpkg-reconfigure -f noninteractive unattended-upgrades
Verify the daily upgrade timer is running:
systemctl status apt-daily-upgrade.timer --no-pager
One important production detail: open /etc/apt/apt.conf.d/50unattended-upgrades and make sure Unattended-Upgrade::Automatic-Reboot stays "false" on single-server boxes. You want security patches applied automatically every night, and you want humans choosing when a kernel reboot happens so your server doesn't restart right in the middle of a database migration or traffic spike (see our safe Ubuntu server update and reboot guide for the exact reboot routine).
2. Create a Dedicated Non-Root Deploy User
Never run web apps, Git pulls, Node builds, or Composer as root. If an npm postinstall script or a buggy PHP upload handler ever gets compromised under root, the attacker owns the entire operating system immediately. Running your application under a dedicated non-root user limits the blast radius cleanly.
Create one dedicated deploy user (we standardize on crab across every server), grant sudo access for admin tasks, and copy your SSH public key:
adduser --disabled-password --gecos "" crab
usermod -aG sudo crab
mkdir -p /home/crab/.ssh
cp /root/.ssh/authorized_keys /home/crab/.ssh/authorized_keys
chown -R crab:crab /home/crab/.ssh
chmod 700 /home/crab/.ssh && chmod 600 /home/crab/.ssh/authorized_keys
Stop and test right now in a second terminal window before you touch sshd:
ssh crab@YOUR_SERVER_IP "whoami && groups"
Never lock down sshd until you've verified your non-root key login actually works. Locking yourself out of a brand-new VPS five minutes in is a rite of passage you don't need to repeat.
3. Harden OpenSSH (And Catch Ubuntu 24.04's 50-cloud-init.conf Gotcha)
On Ubuntu 24.04 and 26.04, always place your SSH hardening rules in /etc/ssh/sshd_config.d/ instead of editing /etc/ssh/sshd_config directly. That way the next openssh-server security patch installs cleanly without popping up an interactive 3-way merge prompt.
Here is the gotcha that trips up even senior Linux engineers on Ubuntu 24.04: many cloud providers drop /etc/ssh/sshd_config.d/50-cloud-init.conf containing PasswordAuthentication yes. In OpenSSH, the first matching directive wins — which means a file named 99-hardening.conf is parsed after 50-cloud-init.conf and silently ignored!
Check for existing overrides first:
sudo grep -rn "PasswordAuthentication" /etc/ssh/sshd_config /etc/ssh/sshd_config.d/
Name your override 00-hardening.conf so it always wins first:
sudo tee /etc/ssh/sshd_config.d/00-hardening.conf >/dev/null <<'EOF'
PermitRootLogin no
PasswordAuthentication no
KbdInteractiveAuthentication no
PubkeyAuthentication yes
MaxAuthTries 4
ClientAliveInterval 300
ClientAliveCountMax 2
X11Forwarding no
EOF
Now validate syntax with sshd -t and inspect the actual effective configuration with sshd -T before reloading:
sudo sshd -t
sudo sshd -T | grep -E '^(permitrootlogin|passwordauthentication|kbdinteractiveauthentication)'
sudo systemctl reload ssh
Every one of those three lines should print no. Note also that on Ubuntu 24.04, SSH uses systemd socket activation (ssh.socket) by default — systemctl reload ssh still works cleanly, and if you ever change the SSH port you must update the socket unit too.
4. Configure UFW Firewall (Default Deny Incoming)
Lock the firewall down to SSH, HTTP, and HTTPS — nothing else:
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow 22/tcp comment 'SSH'
sudo ufw allow 80/tcp comment 'HTTP'
sudo ufw allow 443/tcp comment 'HTTPS'
sudo ufw --force enable
sudo ufw status verbose
If you run a database (PostgreSQL, MySQL) or Redis on the same VPS, never open 5432, 3306, or 6379 in UFW. There is zero reason for a database port to be reachable from the public internet. When you want to run queries from TablePlus, DataGrip, or psql on your laptop, open an encrypted SSH tunnel instead:
ssh -N -L 5432:127.0.0.1:5432 crab@YOUR_SERVER_IP
One extra warning if you ever run Docker on the same machine: Docker manipulates iptables directly and bypasses UFW rules unless you explicitly bind container ports to 127.0.0.1:PORT:PORT. Running native Ubuntu packages without Docker avoids that entire class of accidental exposure. See Firewall if you want a clean UI to review and edit UFW rules across multiple servers.
5. Add Rate-Limiting or Fail2ban Against SSH Noise
With PasswordAuthentication no and Ed25519 keys, brute-force bots cannot break into your server — mathematically, guessing an Ed25519 key is impossible. Still, bots will happily burn CPU cycles and spam your logs with thousands of failed handshakes per day. Either use UFW's built-in rate limit (sudo ufw limit 22/tcp) or install fail2ban:
sudo apt-get install -y fail2ban
sudo tee /etc/fail2ban/jail.local >/dev/null <<'EOF'
[sshd]
enabled = true
backend = systemd
maxretry = 5
bantime = 1h
findtime = 10m
EOF
sudo systemctl enable --now fail2ban
sudo fail2ban-client status sshd
Notice backend = systemd — on Ubuntu 24.04+, SSH logs live in journald rather than a guaranteed /var/log/auth.log file, so setting backend = systemd keeps fail2ban starting cleanly on every boot.
6. Add a Swap File on 1–4 GB VPS Instances
Small VPSes (1–4 GB RAM) almost never ship with swap enabled. Everything runs smoothly until the day composer install, pnpm run build, or a brief traffic spike pushes RAM to 101% for three seconds — and the Linux OOM killer steps in and murders the biggest process on the box, which is almost always MySQL or PostgreSQL.
Adding a 2 GB swap file with low swappiness keeps your server strictly in RAM during normal traffic while giving you a safety cushion during deploys:
sudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
sudo tee /etc/sysctl.d/99-swap.conf >/dev/null <<'EOF'
vm.swappiness=10
vm.vfs_cache_pressure=50
EOF
sudo sysctl --system
Verify with swapon --show and free -h. You should see /swapfile mounted and 0B used while idle.
7. Set Timezone to UTC and Confirm NTP Clock Sync
Always run production servers in UTC. Running servers in a local timezone with Daylight Saving Time transitions is a classic way to trigger duplicate billing crons at 2 a.m. or lose your mind correlating logs across services during an outage:
sudo timedatectl set-timezone UTC
timedatectl status
Confirm System clock synchronized: yes and NTP service: active. Accurate clocks also matter for Let's Encrypt TLS certificates, JWT expiration checks, TOTP 2FA tokens, and S3/R2 signed request headers.
8. Cap journald Disk Usage Before Logs Fill Your Root Partition
One crash-looping queue worker or misbehaving daemon can pump gigabytes into /var/log/journal over a weekend until your root partition hits 100% and your database refuses writes. Cap journald once on day one:
sudo mkdir -p /etc/systemd/journald.conf.d
sudo tee /etc/systemd/journald.conf.d/size.conf >/dev/null <<'EOF'
[Journal]
SystemMaxUse=500M
MaxRetentionSec=14day
EOF
sudo systemctl restart systemd-journald
Check current journal disk usage anytime with journalctl --disk-usage. If you also write application logs to disk (like Laravel's storage/logs/), use daily log rotation or logrotate so app logs are bounded too.
9. Install Only the Services You Need & Audit Listening Sockets
Resist the urge to install every database and runtime up front. Every extra daemon is RAM burned and another package to patch. After installing your web server (like Caddy), runtime (PHP 8.4 or Node.js), and database, run a socket audit:
sudo ss -tulpn
Verify three things:
- Only
sshd(22) andcaddy(80,443) bind to0.0.0.0/::. postgres,mysqld, andredis-serverbind strictly to127.0.0.1.- No unexpected human users or stray SSH keys exist on the box (see our Ubuntu list users & SSH key audit guide).
Also check df -h and lsblk to make sure your cloud provider actually expanded the root partition to the full advertised disk size — occasionally a resized VPS volume needs sudo resize2fs /dev/sda1 before the extra gigabytes appear.
10. Quick Kernel Network Hygiene (BBR + SYN Cookies)
Finally, drop a tiny /etc/sysctl.d/99-network.conf for SYN-flood protection and Google's BBR TCP congestion control. BBR makes a noticeable difference for users connecting over high-latency or slightly lossy mobile networks:
sudo tee /etc/sysctl.d/99-network.conf >/dev/null <<'EOF'
net.ipv4.tcp_syncookies = 1
net.core.default_qdisc = fq
net.ipv4.tcp_congestion_control = bbr
EOF
sudo sysctl --system
Ubuntu 24.04 Server Setup Checklist — 60-Second Verification Table
Run these eight one-liners on any server to confirm nothing was missed:
| Security / Ops Check | Verification Command | Expected Output |
|---|---|---|
| Security upgrades active | systemctl is-active apt-daily-upgrade.timer |
active |
| Non-root SSH login works | ssh crab@YOUR_IP whoami |
crab |
| Root & password SSH off | sudo sshd -T | grep -E '^(permitrootlogin|passwordauthentication)' |
both no |
| UFW firewall enabled | sudo ufw status |
Status: active (only 22, 80, 443) |
| Fail2ban active | sudo fail2ban-client status sshd |
sshd jail running |
| Swap mounted | swapon --show |
/swapfile listed |
| UTC clock synced | timedatectl | grep -E 'Time zone|synchronized' |
UTC & yes |
| Journal capped | journalctl --disk-usage |
under 500M |
| No public DB ports | sudo ss -tulpn | grep -E '3306|5432|6379' |
127.0.0.1 only |
Automate This Checklist Without Giving Up Server Ownership
Running through this checklist manually once is worth its weight in gold — you learn how Ubuntu 24.04 and 26.04 actually tick under the hood, and you'll never feel intimidated SSH-ing into a production box again. When you're spinning up your third or fifth server, though, typing the same commands by hand gets repetitive fast.
Crabsmith is a hosted control panel that provisions Ubuntu 24.04 and 26.04 servers over agentless SSH using readable Bash scripts — creating the dedicated crab user, managing SSH keys (SSH keys), configuring UFW (Firewall), and installing only the services you pick in Services. Zero background agent, zero bloat, and zero lock-in.
Try it on your next Ubuntu VPS with a 7-day free trial (no credit card required), or browse Getting started and Servers.