Hardening a fresh Ubuntu server before you put anything on it
7 April 2026 · CodeGenexis
A fresh VPS starts receiving brute-force login attempts within minutes of getting a public IP — before you have deployed anything worth stealing. None of the defences are exotic. The problem is that they are boring, so they get skipped, and the server that was 'temporary' in 2023 is still running production in 2026 with password login enabled.
The twenty-minute checklist
- Create a non-root user with sudo, put your SSH key on it, then disable root login and password authentication entirely.
- Enable ufw: deny incoming by default, allow SSH, 80 and 443, nothing else until something needs it.
- Install fail2ban with a long ban time — the default config alone removes most of the noise from your auth log.
- Add a swap file sized to RAM. The out-of-memory killer taking down your database at 3am is a preventable incident.
- Turn on unattended-upgrades for security patches, and reboot on a schedule you control.
We run this on every server we provision, scripted, before the first application package is installed. It does not make a server invulnerable — it makes it a harder target than the thousands of unpatched boxes on the same subnet, and it means the predictable failures are already handled the night something odd happens.