What hardening means
Hardening is reducing a system’s attack surface: fewer doors, each one locked, and a record of who comes through. The first steps on almost any server are the same:
- Keep it updated, because most attacks use known, already-fixed vulnerabilities.
- Only run what you need, because every service is a door.
- Allow only the traffic you expect, with a firewall.
- Give every account the least privilege it needs.
- Keep logs, ideally somewhere else too (Lesson 5).
What you now know
- What a server is, and your lab. Services listen on ports and are run by systemd; the lab VM is yours, snapshot included.
- SSH. Keys instead of passwords, no direct root login, and test changes from a second session.
- A web server. nginx serves
/var/www/html, logs every request, and no longer shows its version. - A database server. MariaDB listens on
127.0.0.1, and thewebappaccount can only read and write rows. - DNS, mail, and logs. Resolvers versus authoritative servers, SPF, DKIM, and DMARC, and reading the journal.
Hands-on: harden lab01 and check it
Log in to lab01 over SSH.
1. Updates. Install anything new, and confirm automatic security updates are on (Ubuntu Server enables them by default):
sudo apt update && sudo apt upgrade -y
systemctl status unattended-upgrades --no-pager
2. Only what you need. List running services, and read each name. Anything you cannot explain is worth looking up:
systemctl list-units --type=service --state=running --no-pager
3. A firewall. Ubuntu includes ufw (“uncomplicated firewall”). Allow SSH first, then the web server, and only then turn it on:
sudo ufw allow OpenSSH
sudo ufw allow 'Nginx HTTP'
sudo ufw enable
sudo ufw status verbose
The status shows the default policy, deny incoming and allow outgoing, plus your two rules. The database needs no rule: it only listens on 127.0.0.1 anyway.
4. Accounts. Who can use sudo?
getent group sudo
It should list only you. On a real server, every name here is someone who can do anything.
5. The final check: what is listening?
sudo ss -tulpn
Read each line, as in Networking Fundamentals Lesson 3. You should be able to explain every one:
| Address and port | Service | Why it is OK |
|---|---|---|
0.0.0.0:22 and [::]:22 |
SSH | Keys only, no root login, allowed by the firewall |
0.0.0.0:80 and [::]:80 |
nginx | Your web page, allowed by the firewall |
127.0.0.1:3306 |
MariaDB | Only reachable from the server itself |
127.0.0.53:53 (and 127.0.0.54:53) |
systemd-resolved | The server’s own local DNS helper |
On some systems you may also see a small DHCP client on UDP port 68: it keeps the VM’s network address. If you see anything else, find out what it is before moving on.
6. Snapshot the result. Shut down with sudo poweroff and take a second snapshot (or clone) named hardened.
You just did a first-pass hardening of a real Linux server: patched it, checked its services, put a firewall in front, confirmed who has admin rights, and verified every open port. On a real system, this is the same checklist, followed by much more.
Where to go from here
Hardening goes much deeper: HTTPS certificates, intrusion detection, central logging, and configuration benchmarks like the CIS Benchmarks. Your lab01 is a safe place to keep practicing: break it, then restore a snapshot.
Bring questions, and screenshots with private details removed, to the community Discord with the Join Discord button at the top of the page.
Next steps:
- Security Concepts for the defensive vocabulary and rules of engagement, if you have not taken it yet.
- AI Fundamentals for the AI-powered tools that now sit on top of many of these logs.