Infrastructure
Every provider gives you a root password and an open SSH port. Bots start guessing within the hour. The fix is not complicated, but it has to happen before the first deploy, and in the right order so you never lock yourself out.
I keep the whole procedure in a single idempotent script so a server can be rebuilt from scratch in ten minutes. That script is also the documentation: anyone on the team can read what the server looks like.
Below is the checklist the script implements. If you only do the first five steps, you are already ahead of most production servers I audit.
Hardening is not a one-time event. Pair this checklist with automatic security updates, monitoring and a monthly review of logs, and keep the script in version control so every change is visible.

The checklist
01. Access
Create a sudo user, install your SSH key, then disable root login and password authentication.
Move SSH behind a non-default port and limit it to known IPs when you can.
02. Network
Default-deny firewall with nftables or ufw, opening only 22, 80 and 443.
fail2ban on SSH and Nginx, with aggressive bans for repeated failures.
03. System
Unattended security upgrades, NTP, a swap file and log rotation.
Encrypted off-site backups, and a restore you have actually tested.



