Every "we got hacked" post-mortem I've read in the last five years has the same root cause: an unpatched package, an SSH password that was hunter2, an exposed…

Every "we got hacked" post-mortem I've read in the last five years has the same root cause: an unpatched package, an SSH password that was hunter2, an exposed admin port, or a service running as root that didn't need to. None of them were exotic zero-days. They were the boring failures that a basic hardening pass would have prevented. This article is that pass. I'm not going to give you a 200-item CIS checklist and call it a strategy.

I'm going to give you the 20% of hardening that prevents 80% of real attacks, with the actual commands and configs you can copy-paste onto a fresh Ubuntu/Debian box. The goal isn't to pass an audit. The goal is to make your server boring to attackers so they move on to an easier target. $32 Prerequisites A freshly installed Debian 12 or Ubuntu 22.04+ server. The patterns transfer to RHEL-family with package-name substitutions (dnf instead of apt, firewalld instead of ufw). Root or sudo access.

We'll create a non-root user partway through. A second terminal session open while you make SSH changes. The first time you lock yourself out of SSH is the last time you skip this step. An SSH key pair generated locally: ssh-keygen -t ed25519 -a 100 -C "you@laptop". Ed25519 is the right choice in 2025; RSA still works but the keys are larger and slower. You also need an out-of-band access method-a cloud provider's serial console, an IPMI session, or a VPS provider's web VNC.

When SSH dies, this is how you get back in.

$33 $34 $35 $36 $37 $38 $39 $3a $3b $3c $3d $3e $3f Testing and Verification After hardening, run a verification pass: # CIS scan sudo oscap xccdf eval --profile cis_level1_server \ --report /tmp/cis-report.html \ /usr/share/xml/scap/ssg/content/ssg-ubuntu2204-ds.xml # Ly Lynis (third-party hardening scanner) sudo apt-get install -y lynis sudo lynis audit system --quick # Review /var/log/lynis-report.dat and /var/log/lynis.log # Verify firewall sudo ufw status verbose # Verify SSH config sudo sshd -T | grep -E 'permitrootlogin|passwordauthentication|allowusers' # Verify no listening on 0.0.0.0 except expected sudo ss -tulpn | grep '0.0.0.0:*' # Verify sysctl sudo sysctl net.ipv4.tcp_syncookies kernel.kptr_restrict kernel.dmesg_restrict # Verify audit rules loaded sudo auditctl -l | wc -l These commands give you a snapshot of the current hardening state.

Source disclosure

This is a source-linked briefing. Read the original report from Dev Community .