Hardening you cannot prove is hardening you cannot trust. This final lesson closes the loop: test what you built, score it, decide what is acceptable, and set up the habits that keep it that way.
Test from outside (your own servers only)
Run these from a different machine against servers you own or are authorised to test.
nmap -Pn -sS -p- SERVER_IP # only the intended ports should answer
nmap -Pn --script ssh2-enum-algos -p 22 SERVER_IP # SSH algorithms offered
ssh-audit SERVER_IP # clear pass/warn/fail on SSH settings
testssl.sh --fast SERVER_IP:443 # TLS configurationThen try the attacks that should now fail:
- SSH with a password: refused. SSH as root: refused.
- RDP from an address outside your admin range: refused.
- A random high port: no response.
A failed attempt is a passed test.
Test from inside
Ubuntu
sudo ss -tulpn # listeners match the plan
sudo sshd -T | grep -Ei 'permitroot|passwordauth|allowgroups'
sudo ufw status verbose
sudo aa-status | head
sudo auditctl -l | headWindows
Get-NetTCPConnection -State Listen | Sort-Object LocalPort | Format-Table LocalPort,OwningProcess
Get-NetFirewallProfile | Select-Object Name,Enabled,DefaultInboundAction
Get-SmbServerConfiguration | Select-Object EnableSMB1Protocol,RequireSecuritySignature
Get-MpComputerStatus | Select-Object RealTimeProtectionEnabled,IsTamperProtected
auditpol /get /category:* | Select-String "Process Creation|Logon"Score it
- Ubuntu:
sudo lynis audit systemand compare the hardening index with the one you recorded in lesson 6. On Ubuntu Pro,sudo usg audit cis_level1_server. - Windows: run Policy Analyzer from the Security Compliance Toolkit against the Microsoft baseline, and compare against the current CIS Benchmark for your server version.
- Both: an authenticated vulnerability scan (OpenVAS/Greenbone, Nessus, or similar) to find missing patches and weak configuration you did not think of.
Treat benchmark failures as decisions: fix it, accept it with a written reason and an owner, or schedule it. Compliance is not security, but an honest benchmark is a very good checklist.
The 3-hour acceptance checklist
| # | Ubuntu | Windows |
|---|---|---|
| 1 | Snapshot and rollback tested | Snapshot and rollback tested |
| 2 | Key-only SSH, no root, AllowGroups, sshd -T verified |
LAPS active, separate admin accounts, Protected Users |
| 3 | Default-deny firewall, outside scan clean | Firewall on, default block inbound, RDP scoped and NLA on |
| 4 | Unattended security updates on, reboot plan set | Patch cadence set, SMBv1 and PowerShell v2 gone |
| 5 | Services sandboxed, packages trimmed | Print Spooler and unused roles removed |
| 6 | AppArmor enforcing, mount and kernel settings applied | Defender healthy, ASR rules in audit or block |
| 7 | auditd rules loaded, journald persistent | Audit policy, command-line and script-block logging on |
| 8 | Logs forwarded off the host | Sysmon installed, logs forwarded off the host |
| 9 | Lynis index recorded before and after | Baseline compared with Policy Analyzer |
| 10 | Backup restored successfully once | Backup restored successfully once |
If you can tick the row for your platform, you are done for this pass.
Keep it hardened
A good rhythm is simple:
- Weekly: review alerts and failed-login trends; confirm patches applied; check backup success.
- Monthly: review local admins and sudoers; diff listening ports against the baseline; check certificate expiry; run the scanner.
- Quarterly: restore a backup into a test environment; re-run the benchmark; review and renew documented exceptions; rehearse your incident runbook.
- On every change: update the baseline and the automation.
Keep an exceptions log: control skipped, reason, owner, review date. Unowned exceptions become permanent holes.
A minimal incident runbook
Write this down now, while it is calm:
- Detect and decide: who declares an incident and how?
- Contain: isolate the host (firewall rule, VLAN, or hypervisor network disconnect) without powering off if you can avoid it.
- Preserve evidence: capture memory if feasible, snapshot the disk, and secure the logs you forwarded off-host.
- Eradicate and rebuild: prefer rebuilding from a hardened image and restoring data from a known-good backup over "cleaning" a compromised server.
- Rotate credentials that the server could access, then review how they got in.
- Learn: write down what the logs showed and what you will change.
Common mistakes
- Locking yourself out by changing SSH, the firewall or RDP without a console and a second session.
- Hardening once and never again (drift).
- Chasing a perfect score and breaking the application. Availability matters too.
- Skipping the logs. Prevention fails; detection is how you find out.
- Forgetting the backups are an attack target.
🧪 Final lab: the hardening report
- On each server, run the outside and inside tests and record the results.
- Compare your before baseline (lesson 1) and after Lynis and Policy Analyzer scores.
- Complete the acceptance checklist for your platform, marking each item pass, accepted exception, or to do.
- Write a one-page hardening report: what you changed, what you tested, what you accepted, and your next three improvements.
- Put your key settings into automation (Ansible or Group Policy) so a rebuilt server comes back the same.
Checkpoint
- Name three outside tests that should fail on a hardened server.
- Why is a benchmark result a "decision" rather than a pass/fail?
- What belongs in an exceptions log entry?
- Why prefer rebuilding a compromised server over cleaning it?
- Which three habits in the maintenance rhythm would you start this week?