Module 2 · Services, SSH and Hardening · Lesson 8 of 10

Guided project: harden an Ubuntu server

Baseline, update, key-only SSH, a UFW firewall that keeps you in, trimmed services, and a reboot test.

In this lesson · about 45 minutes

  • Record a baseline before changing anything
  • Apply SSH and firewall hardening without losing access
  • Prove the result with an access test matrix and a reboot

Whiteboard · watch and try

Whiteboard: the safe order of steps

Press Play. The tutor writes the order that keeps you from locking yourself out.

5 steps
Press Play and the tutor will talk you through it while writing on the board. Pause any time to write on the board yourself.

Tip: press Pause, then use the pen to work along on the board. Space plays and pauses; Ctrl+Z undoes your last mark.

Try it · watch it happen

The firewall is a guard with a guest list

Tick rules and enable the firewall in different orders. Send the visitors and see who gets in. Can you lock yourself out?

The guard's guest list

Default rule: turn away anyone who isn't on the list (deny incoming).

At the gategate wide open

You (admin laptop)10.10.10.20 → port 22
A shop customer198.51.100.7 → port 80
A password guesser203.0.113.45 → port 22
Someone probing the database203.0.113.45 → port 5432
With the guard off, everyone walks straight in. Tick the rules you want, then enable the firewall.

Setup: an Ubuntu VM with OpenSSH and UFW, a second client machine, and a written baseline. Take a snapshot first and keep a console open (the VM's own screen, not SSH) so you can recover if you lock yourself out.

The six steps

  1. Baseline. Snapshot the VM. Record users, group membership, running services, listening ports and what the host is for.
  2. Update and separate duties. Apply updates from trusted repositories and check whether a restart is needed. Create a named administrator; do routine work without sudo.
  3. Key-based SSH. Set up key login, validate the config with sudo sshd -t, test another session, and only then turn off password and root logins. Check drop-in files in /etc/ssh/sshd_config.d/, which can override the main file.
  4. Firewall. Allow SSH from your real management client IP before enabling UFW. Don't copy an example address without replacing it.
  5. Trim and watch. Disable only services you've shown are unnecessary. Read logs with journalctl and check AppArmor with sudo aa-status. Never disable a protection just to make an unexplained error go away.
  6. Prove it. Test approved login, denied access from another client, service health, and everything again after a reboot. Save evidence, then remove temporary users or restore the snapshot.

Hands-on lab (simulated terminal)

Project lab: steps 1 to 4

You're admin on ubuntu-lab (10.10.10.5). Your management client is 10.10.10.20. A console session is open as backup. Sudo password: lab.

Step 1 of 9. Type each command and press Enter. Nothing runs on your computer.

Project lab: steps 1 to 4

1. Step 1 baseline: list listening TCP and UDP ports with processes.

admin@ubuntu-lab:~$

Performance-based question (PBQ)

Step 6: the access test matrix

After rebooting, you ran these tests. Decide whether each result is what a hardened server should do.

Mark each result.

  • Key login from 10.10.10.20 works
  • SSH from 10.10.10.30 (another lab client) times out
  • Password login from 10.10.10.20 says 'Permission denied (publickey)'
  • curl http://10.10.10.5 from 10.10.10.30 returns 200 OK
  • After reboot, systemctl is-active nginx says inactive
  • ssh root@10.10.10.5 from 10.10.10.20 logs in
0 of 6 answered

Noviq Academy is free and for learning. Every terminal here is simulated and every log is synthetic. Practise on a disposable VM with a snapshot, never on a production server. Ubuntu is a trademark of Canonical Ltd.; this course is independent of Canonical.