Labs · Cyber Security
Lab: Mini Capstone: Harden, Monitor and Back Up One Lab Server End to End, Then Prove Every Control Works
Course: Cyber Security · Chapter 45: Practice Exercises with Hints
Chapter 45 is practice exercises with hints; this capstone combines the defensive labs into one server you harden, monitor, back up and verify.
Chala mitrano! You have learned many separate skills. Real jobs need them together: one server, fully protected, with proof. Today is our capstone: we harden, monitor and back up one server, then test every control like an auditor would. At the end you will have a scorecard you can show in an interview. Chala, final project!
चला मित्रांनो! तुम्ही अनेक वेगवेगळी skills शिकलात. खऱ्या jobs मध्ये ती एकत्र लागतात: एक server, पूर्ण protected, proof सोबत. आज आपला capstone: एक server harden, monitor आणि back up करणार, मग auditor सारखं प्रत्येक control test करणार. शेवटी तुमच्याकडे interview मध्ये दाखवता येईल असं scorecard असेल. चला, final project!
चलो दोस्तों! आपने कई अलग-अलग skills सीखीं। असली jobs में वो साथ में चाहिए: एक server, पूरी तरह protected, proof के साथ। आज हमारा capstone: एक server को harden, monitor और back up करेंगे, फिर auditor की तरह हर control test करेंगे। आख़िर में आपके पास interview में दिखाने लायक scorecard होगा। चलो, final project!
Suppose we are…
Suppose we have just been hired as a junior security engineer at Nykaa, and our manager hands us one new Ubuntu server: "Make it production-ready. Harden it, make sure we would notice an intruder, make sure we can recover it, and show me proof for each." This capstone is that first assignment, done on our own lab VM.
Goal of this lab
By the end you will have one Ubuntu VM with:
- Harden: all updates, automatic security updates, key-only SSH, no root login, UFW, fail2ban, no extra sudo or SUID (Labs 23, 26, 32).
- Monitor: auditd watching identity, sudoers and SSH config (Lab 36).
- Back up: a daily compressed backup of
/etcand/var/wwwwith 7-day retention, and a successful restore test. - A one-page scorecard: control, command used to verify, result, date.
What you need (all free)
- A fresh snapshot of your own Ubuntu Server VM (take one named
before-capstone), reachable over SSH from your laptop. - Notes from Labs 23, 26, 32 and 36. About 90 minutes; you can split it over two days.
Safety and ethics
Use only your own lab VM. Keep one SSH session open until each SSH or firewall change is verified from a new session, and keep the before-capstone snapshot until the scorecard is complete.
Part 1: harden (hints, details are in the earlier labs)
-
Updates and automatic security updates (Lab 23):
sudo apt update && sudo apt upgrade -y && sudo apt install -y unattended-upgrades -
Key-only SSH and no root login with
/etc/ssh/sshd_config.d/10-keys-only.conf, tested withsshd -tand a second session (Lab 32). - UFW: allow OpenSSH (and
Nginx Fullif you run a web server), default deny incoming, enable (Lab 32). - fail2ban sshd jail with
jail.local, test ban and unban203.0.113.9(Lab 32). - sudo and SUID review:
getent group sudo,sudo grep -rn NOPASSWD /etc/sudoers /etc/sudoers.d/, save~/suid-baseline.txt(Lab 26).
Part 2: monitor
- auditd with
/etc/audit/rules.d/lab.rulesfor identity, sudoers and sshd_config, loaded withaugenrules --load(Lab 36). - Trigger one safe event (
sudo touch /etc/ssh/sshd_config) and find it withsudo ausearch -k sshd_config -i | tail -n 5.
Part 3: back up and restore
-
Create a backup folder only root can read:
sudo mkdir -p /root/backups && sudo chmod 700 /root/backups -
Create the backup script:
sudo tee /usr/local/sbin/daily-backup.sh > /dev/null <<'SCRIPT' #!/bin/bash set -euo pipefail D=$(date +%F) tar -czf /root/backups/server-$D.tgz /etc /var/www 2>/dev/null || tar -czf /root/backups/server-$D.tgz /etc find /root/backups -name 'server-*.tgz' -mtime +7 -delete SCRIPT sudo chmod 700 /usr/local/sbin/daily-backup.sh sudo /usr/local/sbin/daily-backup.sh && sudo ls -lh /root/backupsWhat you should see: a file like
server-2026-10-08.tgzof a few MB. -
Schedule it every day at 02:30 (server time):
echo "30 2 * * * root /usr/local/sbin/daily-backup.sh" | sudo tee /etc/cron.d/daily-backup -
Restore test. A backup is only real when a restore works. Extract to a test folder and compare one file:
sudo mkdir -p /tmp/restore-test sudo tar -xzf /root/backups/server-$(date +%F).tgz -C /tmp/restore-test etc/ssh/sshd_config.d sudo diff -r /etc/ssh/sshd_config.d /tmp/restore-test/etc/ssh/sshd_config.d && echo "RESTORE OK"What you should see:
RESTORE OK. -
Copy the backup off the server (a backup on the same disk dies with the disk). On the server, hand a copy to your user; then download it from your laptop and remove the copy:
sudo install -m 600 -o $USER /root/backups/server-$(date +%F).tgz ~/server-backup.tgzFrom your laptop:
scp student@<vm-ip>:server-backup.tgz ., then on the serverrm ~/server-backup.tgz.
Part 4: prove it (the scorecard)
-
Run each check and fill the scorecard with Control, Verify command, Expected, Result, Date:
apt list --upgradable 2>/dev/null | wc -l # expect 1 (only the "Listing..." line) sudo sshd -T | grep -E "passwordauthentication|permitrootlogin" # expect no / no sudo ufw status | head -n 1 # expect Status: active sudo fail2ban-client status sshd | grep "Currently banned" sudo auditctl -l | wc -l # expect 5 or more sudo ls /root/backups # expect today's fileWhat you should see: every line matches the expected value. Anything that does not is your to-do list.
-
Final test from your laptop:
ssh -o PubkeyAuthentication=no student@<vm-ip>must fail withPermission denied (publickey), and your normal key login must work.
Ravindra Bagale's Tip
Put the scorecard, your backup script and your auditd rules in a private Git repository or a PDF. In an interview, "here is the checklist I applied and the proof for each control" is far stronger than "I know Linux security". Kaam dakhva, fakt bolu naka!
Ravindra Bagale's Tip – मराठी
Scorecard, तुमचा backup script आणि auditd rules private Git repository किंवा PDF मध्ये ठेवा. Interview मध्ये "हा मी लावलेला checklist आणि प्रत्येक control चा proof" हे "मला Linux security येते" पेक्षा खूप जास्त प्रभावी आहे. काम दाखवा, फक्त बोलू नका!
Ravindra Bagale's Tip – हिंदी
Scorecard, अपना backup script और auditd rules private Git repository या PDF में रखो। Interview में "ये रहा मेरा लगाया checklist और हर control का proof" कहना "मुझे Linux security आती है" से कहीं ज़्यादा असरदार है। काम दिखाओ, सिर्फ बोलो मत!
Common mistakes
| Mistake | What happens | Fix |
|---|---|---|
| Doing all changes, then testing at the end | You cannot tell which change broke SSH | Test after each part |
| Backups only on the same server | A disk failure or ransomware destroys both | Copy off the server (step 12) |
| Never testing a restore | You find out the backup is broken during a real incident | Restore test every time you change the script |
% signs in a crontab line |
cron cuts the command at % |
Put the logic in a script, as in step 9 |
| No snapshot before starting | No way back from a mistake | Take before-capstone first |
Self-check checklist
0 of 6 done
Try-at-home challenge
Write the recovery steps (a "runbook") for this situation: the VM's disk is lost and you must rebuild the server from a fresh Ubuntu install and your off-server backup. What are the steps, and how long would they take?
Check your answer
1) Install fresh Ubuntu and updates. 2) Copy server-backup.tgz to the new VM. 3) Extract to /tmp/restore and copy back only what you need: /etc/ssh/sshd_config.d, /etc/ufw, /etc/fail2ban/jail.local, /etc/audit/rules.d, /etc/cron.d/daily-backup, the script and /var/www. 4) Reinstall packages (ufw, fail2ban, auditd, nginx). 5) Restart services and re-run the scorecard checks. Timing it is the point: measure it on your VM to get your real recovery time (RTO).
Samjla ka? Harden, monitor, back up, restore, prove it on one page. Aata pudhe jaauya: Chapter 46 prepares you to explain all this in an interview.