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.
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
| 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-rsas 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.
- Snapshot first. Take a VM snapshot or backup, and confirm you know how to restore it.
- 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.
- One change at a time on anything that matters. Apply, test, then continue. Batch changes only in a throwaway lab.
- Test in a second session. Open a new SSH or RDP session to prove access works before you close the working one.
- 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:
- What does this server do, and what data does it hold?
- Who or what must reach it, and from where? (This becomes your firewall.)
- Who administers it, and how? (This becomes your SSH, sudo and RDP policy.)
- What would an attacker want from it, and what is the worst day look like?
- 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
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 loginsWindows Server (elevated 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 5Save 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
- 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.
- Run the baseline commands above and save the output to a file.
- Write your five threat-model answers for each server in a few lines.
- Confirm you can reach each VM's console without using SSH or RDP.
Checkpoint
- Name the five layers of defence in depth used in this track.
- Why do you keep a second session open while changing SSH or RDP settings?
- What three things should exist before you start hardening a server?
- Why does a threat-model answer about "who must reach this server" drive your firewall?
- What should you do with a listening service nobody can justify?