Lesson 1 of 12 · 10 min · Intermediate

Plan the three hours: threat model, baseline and rollback

Why hardening works, the order we follow, the safety rules that stop you locking yourself out, and the baseline inventory you capture on Ubuntu and Windows before changing anything.

In this lesson you will

  • Explain why hardening removes the cheap wins attackers rely on
  • Follow a 3-hour plan that covers Ubuntu and Windows in a safe order
  • Apply the safety rules: snapshot, console access, one change at a time
  • Capture a baseline inventory of services, ports and accounts

Welcome to Server Hardening in 3 Hours. By the end you will have taken a default Ubuntu Server and a default Windows Server and turned each into a machine that is much harder to break into, much easier to monitor, and much quicker to recover. Every step is a command or setting you can copy, with a way to verify it and a way to back it out.

Authorised systems only. Practise on your own VMs, a lab, or servers you are explicitly responsible for. Change production only through your normal change process.

Why hardening works

Most server breaches are not clever. They start with the same handful of cheap wins: a management port open to the internet, a password that can be guessed, a flaw that already has a patch, an account with far more rights than it needs, and no logs to notice any of it. Hardening removes those cheap wins, so an attacker has to spend real effort, and effort is what gets them noticed.

Defence in depth for a server

The five layers above are the spine of this track. No single layer is perfect. The point is that an attacker who gets past one still meets the next, and your logs record the attempt.

The three-hour plan

The 3-hour hardening plan

Block Lessons What you finish with
Prepare 1 Baseline, snapshot, rollback plan
Ubuntu 2 to 6 Key-only SSH, default-deny firewall, auto-patching, sandboxed services, auditd, logs, a Lynis score
Windows 7 to 10 Removed legacy protocols, LAPS, locked-down RDP, Defender and ASR, Credential Guard, audit policy, Sysmon
Both 11 to 12 Secrets, TLS, backups, drift control, and a verification checklist

Only run one OS? Skip the other half. Lessons 1, 11 and 12 apply to both.

Versions. Commands are written for Ubuntu Server 24.04 and 26.04 LTS and Windows Server 2022 and 2025. Where the releases differ, we say so. Ubuntu 26.04 ships sudo-rs as the default sudo, and Windows Server 2025 tightens several defaults (outbound SMB signing, Credential Guard on supported hardware).

Five safety rules (read these twice)

Hardening is the one kind of work where a typo can lock you out of your own server.

  1. Snapshot first. Take a VM snapshot or backup, and confirm you know how to restore it.
  2. Keep a way in that is not the thing you are changing. Have console access (hypervisor console, cloud serial console, iLO/iDRAC) before you touch SSH, firewall or RDP.
  3. One change at a time on anything that matters. Apply, test, then continue. Batch changes only in a throwaway lab.
  4. Test in a second session. Open a new SSH or RDP session to prove access works before you close the working one.
  5. Write down the back-out. Every risky step in this track states how to undo it. Keep it handy.

Threat model in five questions

You do not need a 40-page document. Answer these in a few lines per server:

  1. What does this server do, and what data does it hold?
  2. Who or what must reach it, and from where? (This becomes your firewall.)
  3. Who administers it, and how? (This becomes your SSH, sudo and RDP policy.)
  4. What would an attacker want from it, and what is the worst day look like?
  5. How would you know if it were compromised, and how fast could you rebuild it?

Step 0: capture the baseline

Before you change anything, record what is there. You will compare against this at the end, and you will often be surprised by what is running.

Ubuntu

bash
lsb_release -a                              # release
uname -r                                    # kernel
sudo ss -tulpn                              # listening ports and owning processes
systemctl list-unit-files --state=enabled   # services that start at boot
dpkg -l | wc -l                             # installed package count
getent group sudo                           # who has sudo
awk -F: '($3==0){print $1}' /etc/passwd     # accounts with UID 0 (should be only root)
last -n 10                                  # recent logins

Windows Server (elevated PowerShell)

powershell
Get-ComputerInfo -Property OsName,OsVersion,WindowsInstallationType
Get-NetTCPConnection -State Listen | Sort-Object LocalPort | Format-Table LocalAddress,LocalPort,OwningProcess
Get-Service | Where-Object Status -eq Running | Sort-Object Name | Select-Object Name,DisplayName
Get-WindowsFeature | Where-Object Installed | Select-Object Name
Get-LocalGroupMember -Group Administrators
Get-HotFix | Sort-Object InstalledOn -Descending | Select-Object -First 5

Save both outputs. A simple table works:

Item Ubuntu Windows
Listening ports you did not expect
Services you cannot explain
Admin or sudo accounts
Last patch date

Quick win. Anything listening that nobody can justify is the first thing to remove. An unused service has no benefits and some risk.

🧪 Lab

  1. Build two VMs: an Ubuntu Server 24.04 or 26.04 and a Windows Server 2022 or 2025 (evaluation ISOs are free). Take a snapshot of each.
  2. Run the baseline commands above and save the output to a file.
  3. Write your five threat-model answers for each server in a few lines.
  4. Confirm you can reach each VM's console without using SSH or RDP.

Checkpoint

  1. Name the five layers of defence in depth used in this track.
  2. Why do you keep a second session open while changing SSH or RDP settings?
  3. What three things should exist before you start hardening a server?
  4. Why does a threat-model answer about "who must reach this server" drive your firewall?
  5. What should you do with a listening service nobody can justify?