⚠️ Without Purple Team collaboration, Red
and Blue often repeat each other's mistakes.
What Does a System Admin &
Security Do?
Confidentiality: private data
Integrity: accurate data
Availability: systems stay up
What Does a System Admin &
Security Do?
Installs & configures systems
Manages users & permissions
Monitors & troubleshoots
What Does a System Admin &
Security Do?
One computer, two systems
Windows & Linux Mint installed
Each system has its own users
What Does a System Admin & Security
Not Do? (AI/LLM)
Never runs AI/LLM unsupervised
Risks confidentiality
Risks integrity & availability
OpenClaw (2026): real incident
“Researchers Expose OpenClaw AI Agent Credential Leak
During Phishing Simulation” (2026) (Source: Cyber Press)
🚨 OpenClaw is a real autonomous AI agent given
shell access and credentials. In a 2026 phishing test, one company's OpenClaw agent
handed over a customer database and forwarded AWS keys in
plaintext.
What Does a System Admin & Security
Not Do? (User Content)
Doesn't own user data
Doesn't manage user software
Admin manages the platform
“Court Rules that Stored Communications Act Applies
to Former Employee Emails” (2013) (Source: CloudNine)
⚠️ In Lazette v. Kulmatycki (2013),
a supervisor read 48,000 of a former employee's
personal emails over 18 months after she returned her company phone.
What Does a System Admin & Security
Not Do? (App Code)
Doesn't write app code
That's the developer's job
Admin runs & secures it
“The $440 Million Software Error at Knight
Capital” (2012) (Source: Henrico Dolfing)
🚨 In 2012, Knight Capital lost
$460 million in 45 minutes after a technician's
manual deployment left old code running on one server.
What Does a System Admin & Security
Not Do? (Snooping)
Root access isn't a license
Doesn't snoop on private data
Ethics, not just capability
Robbins v. Lower Merion School District (2010)
(Source: Wikipedia)
🚨 In the Lower Merion webcam case (2010), a
network technician secretly activated laptop cameras, leading to a
$610,000 settlement.
What Does a System Admin & Security Do? (RACI)
R: Responsible, does the work
A: Accountable, owns outcome
C: Consulted, gives input
I: Informed, kept in loop
Task
Admin
Dev
Sec
User
Patching
R/A
I
C
I
App Code
I
R/A
C
–
Access Review
R
I
A
C
Incident Resp.
R
I
A
I
AI/LLM Use
R
C
A
I
User Data
I
C
C
R/A
Network Setup
R/A
I
C
I
Backups & Snapshots
R/A
I
C
I
System Uptime
R/A
I
C
I
VM Configuration
R/A
I
I
I
If a Sysadmin Doesn't Write App Code and Doesn't
Own User Data, What's Left to Manage?
Manages user accounts
Manages files & storage
Manages installed software
→
The Operating System.
Questions?
Linux vs. other OSes
How Many Operating Systems Exist?
50+ real names shown here
Desktop, mobile & embedded
Many trace to Unix or Linux
Where Is an Operating System Installed?
Not just PCs & phones
Cars, ATMs, appliances too
e.g., embedded Linux in cars
What Sits at the Base of Every System?
Every layer depends on it
Apps can't bypass it
e.g., Windows 11 on laptops
What Does an OS Actually Do?
Manages memory & processes
Manages files & networking
Enforces security & access
Where Does Admin & Security Work Happen?
Across all 7 OSI layers
From cabling to app configs
e.g., Firewall rules (L4)
Where Does the OS Fit in the Network Stack?
Sits at Layer 7, technically
root has elevated privilege
e.g., sshd on a campus server
Admin isn't its own layer – admin tools (iptables,
systemctl, ip) run at L7 like any app, but with elevated
(root) privilege to reach across the boundary and reconfigure
L4–L1 kernel state directly, instead of only using the unprivileged sockets API like an
ordinary app.
$ wsl --status
# --status: default distro, WSL version
$ wsl --version
# --version: WSL, kernel, and build info
$ wsl -l -v
# -l -v: every installed distro, running or not
Open PowerShell
$wsl--status# --status: default distro, WSL version$wsl--version# --version: WSL, kernel, and build info$wsl-l-v# -l -v: every installed distro, running or not
$man nmap # full manual page$nmap-h # quick help summary$nmap--version # check installed version
What Are Some Sample Nmap Calls?
-sn: host discovery only
-p 22,80: specific ports
-A: OS & version detect
$ nmap scanme.nmap.org # default scan
$ nmap -sn scanme.nmap.org # host discovery only
$ nmap -p 22,80 scanme.nmap.org # specific ports
$ nmap -A scanme.nmap.org # OS + version detect
Sample calls against Nmap's own test target (Source: scanme.nmap.org)
What Are Some Sample Nmap Calls?
$nmap scanme.nmap.org # default scan$nmap-sn scanme.nmap.org # host discovery only$nmap-p22,80 scanme.nmap.org # specific ports$nmap-A scanme.nmap.org # OS + version detect
What Does the Output Mean?
Real scan: scanme.nmap.org
4 open ports, OS guessed
31337: a classic 'leet' port
Nmap scan report for scanme.nmap.org (45.33.32.156)
Host is up (0.024s latency) # host responded
Not shown: 996 filtered ports # most ports hidden
PORT STATE SERVICE
22/tcp open ssh # remote login
80/tcp open http # web server
9929/tcp open nping-echo # Nmap's own test service
31337/tcp open Elite # classic "leet" backdoor port
Running: Linux 4.X|5.X # OS guess
Network Distance: 15 hops # hops to target
Live scan output, run by the instructor against scanme.nmap.org (Source: sudo nmap -O scanme.nmap.org, Aug 2026)
What Does the Output Mean?
Nmap scan report for scanme.nmap.org (45.33.32.156)
Host is up (0.024s latency) # host responded
Not shown: 996 filtered ports # most ports hidden
PORT STATE SERVICE
22/tcp open ssh # remote login80/tcp open http # web server9929/tcp open nping-echo # Nmap's own test service31337/tcp open Elite # classic "leet" backdoor port
Running: Linux 4.X|5.X # OS guess
Network Distance: 15 hops # hops to target
$nmap scanme.nmap.org # Nmap's own test target$nmap 10.10.x.x # TryHackMe VPN target$nmap 10.10.x.x # HackTheBox VPN target$nmap192.168.56.101 # local Metasploitable2 VM
Only Scan What You're Authorized to Scan
scanme.nmap.org, THM, HTB
Metasploitable2: your own VM
Nothing else, ever
“The best way to avoid controversy when using
Nmap is to always secure written authorization from the target network representatives
before initiating any scanning.”
🚨 These public sandboxes are the
only systems you may scan. Never point nmap at any
other server, on or off campus, without written authorization.
How Do You Scan Just One Port?
Faster than a full scan
$ nmap -p 80 scanme.nmap.org # scan only port 80
How Do You Detect the OS?
Needs root / sudo privileges
$ sudo nmap -O scanme.nmap.org # guess the target OS
OS Detection: Real Output
Same 4 ports, still open
OS guess: Linux 4.15–5.19
16 hops to the target
$ sudo nmap -O scanme.nmap.org
PORT STATE SERVICE
22/tcp open ssh
80/tcp open http
9929/tcp open nping-echo
31337/tcp open Elite
Device type: general purpose # broad category
Running: Linux 4.X|5.X # OS family guess
OS details: Linux 4.15 - 5.19 # narrower range
Network Distance: 16 hops
Live scan output, run by the instructor against scanme.nmap.org (Source: sudo nmap -O scanme.nmap.org, Aug 2026)
🔴 Red Team: the OS/version guess narrows which known exploits are worth trying against this target.
🔵 Blue Team: the same fingerprint tells defenders what to patch, and whether to suppress it from scanners.
OS Detection: Real Output
$sudo nmap -O scanme.nmap.org
PORT STATE SERVICE
22/tcp open ssh
80/tcp open http
9929/tcp open nping-echo
31337/tcp open Elite
Device type: general purpose # broad category
Running: Linux 4.X|5.X # OS family guess
OS details: Linux 4.15 - 5.19 # narrower range
Network Distance: 16 hops
Heads Up: OS Guesses Aren't Certain
⚠️ Nmap warns that OS-scan results may be
unreliable when it can't find at least one open and one
closed port on the target. Treat the guess as a best estimate, not a certainty.
How Do You Scan All 65,535 Ports?
Slower, but thorough
$ nmap -p- scanme.nmap.org # scan every TCP port
How Do You Look Up Domain Info?
Public registration record
Needs the base domain
$ whois nmap.org # domain registration info
🔴 Red Team: registrant, registrar & name-server info feeds phishing pretexts and social engineering.
🔵 Blue Team: confirms your own domain hasn't expired or been hijacked; profiles lookalike phishing domains.
Heads Up: WHOIS Needs the Base Domain
⚠️ WHOIS looks up the registered
domain, not a subdomain. `whois
scanme.nmap.org` fails with "Malformed request" on some registries;
use the base domain instead.
How Do You Look Up DNS Records?
Resolves hostname to IP
$ dig scanme.nmap.org # DNS lookup
🔴 Red Team: maps mail servers, subdomains & DNS infrastructure to find attack surface.
🔵 Blue Team: verifies DNS resolves correctly and that SPF/DKIM/DMARC anti-phishing records are published.
Questions?
University Domain: Plan VM
Scenario: University Domain
You're the new
sysadmin at Pacific University. Every setup choice below
follows this one VM for the rest of the course.
University Domain, By the Numbers
University of the Pacific, Fall 2025/2024 Fast Facts & Dugoni School newsroom (Source: pacific.edu)
VM Name
Pattern: role-env-number
Lowercase, hyphens only
Must be unique on network
University Domain
Registrar's web server
reg-web01
Instantly IDs owner & role
A vague name like "server1" becomes unmanageable
once you have 50 VMs.
⚠️ Every user gets exactly one
home directory (`/home/<username>`). It's the only
place you're guaranteed write access without `sudo`, which is why every exercise in this
course starts there instead of somewhere like `/etc` or `/var`.
$ mkdir library && cd library
$ cat > index.html << 'EOF'
<h1>Pacific Library Catalog</h1>
<ul><li>Introduction to System
Admin and Security</li></ul>
EOF
Practice: Create the Catalog Page (Ubuntu)
$mkdir library && cd library
$cat > index.html << 'EOF'
<h1>Pacific Library Catalog</h1>
<ul><li>Introduction to System
Admin and Security</li></ul>
EOF
Practice: Serve lib-web01 (Ubuntu)
Serves the current directory
Listens on port 8080
$ python3 -m http.server 8080
Serving HTTP on 0.0.0.0 port 8080 ...
Practice: Serve lib-web01 (Ubuntu)
$python3-m http.server 8080
Serving HTTP on 0.0.0.0 port 8080 ...
🔵 Blue Team: confirming a port from another machine is exactly how you'd verify your own service is actually reachable, not just "should be" reachable on paper.
🔴 Red Team: at a university, attackers scan every public IP for forgotten open ports, like an old admin panel left listening on 8080.
🔵 Blue Team: campus IT firewalls every server down to only the ports a service actually needs. 8080 is a well-known dev/alt-HTTP port and should never be public.
⚠️ nmap now reports port 8080 as
filtered, not `closed`. `closed` means a host
replied "nothing's listening here," while `filtered` means nothing replied at
all, because ufw silently dropped the packet. `curl` just hangs until it
times out.
⚠️ WSL2 is still
real virtualization. A real Linux kernel runs inside
a Microsoft-managed VM, using Hyper-V under the hood, even though you never see a VM
manager window.
WSL2 vs. Virtualization
A real kernel, virtualized
No visible VM manager
Runs via Hyper-V, hidden
⚠️ WSL2 skips a full guest OS. It runs a
real Linux kernel directly, with no separate virtual
BIOS or drivers to install.
$ pwd
/home/comp175user
$ ls -la
# -la: all files, long detail
drwxr-xr-x 4 comp175user library 4096 notes
$ ls -lh
# -lh: sizes in K/M/G, not bytes
Where Am I?
$pwd/home/comp175user$ls-la# -la: all files, long detail
drwxr-xr-x 4 comp175user library 4096 notes
$ls-lh# -lh: sizes in K/M/G, not bytes
Moving Around: cd
cd path, moves you there
cd .. goes up one level
cd ~ jumps to your home
The Standard Linux Folders
Eight core system folders
Blue needs root access
Gray is user-writable
Changing Directory
cd changes location
.. means one level up
~ is always your home
$ cd /home/comp175user
# absolute path: always from root
$ cd ..
# one level up from here
$ pwd
/home
$ cd ~
# jumps straight to your home
$ cd -
# back to the previous directory
Changing Directory
$cd/home/comp175user# absolute path: always from root$cd ..
# one level up from here$pwd/home$cd ~
# jumps straight to your home$cd -
# back to the previous directory
$ sudo apt install -y man-db
# not installed by default
$ man ls
# the full manual page
$ ls --help
# a quick summary, no paging
$ man -k copy
# -k: search man pages by keyword
Getting Help
$sudo apt install -y man-db
# not installed by default$man ls
# the full manual page$ls--help# a quick summary, no paging$man-k copy
# -k: search man pages by keyword
Word Origin: "man"
Finding a File: find
find searches by name
Starts from a given folder
* is a wildcard
$ find /home -name "*.txt"
/home/comp175user/catalog/checkout.txt
$ find /home -type d
# -type d: directories only, no files
$ find /home -mtime -1
# -mtime -1: modified in the last day
Finding a File: find
$find/home-name"*.txt"/home/comp175user/catalog/checkout.txt$find/home-type d
# -type d: directories only, no files$find/home-mtime -1
# -mtime -1: modified in the last day
Searching Text: grep
grep searches inside files
-r searches every subfolder
-i ignores upper/lowercase
$ grep "restock" checkout.txt
Restock mystery section
$ grep -ri "error" /var/log
# -r: every subfolder, -i: any case
$ grep -c "error" app.log
# -c: count the matches, not show them
Searching Text: grep
$grep"restock" checkout.txt
Restock mystery section
$grep-ri"error"/var/log# -r: every subfolder, -i: any case$grep-c"error" app.log
# -c: count the matches, not show them
$ sudo chown comp175user catalog.txt
# owner only, group untouched
$ sudo chgrp library catalog.txt
# group only, owner untouched
$ sudo chown comp175user:library catalog.txt
# owner and group in one call
$ sudo chown -R comp175user /srv/lib
# -R: every file in the folder too
Changing Ownership
$sudo chown comp175user catalog.txt
# owner only, group untouched$sudo chgrp library catalog.txt
# group only, owner untouched$sudo chown comp175user:library catalog.txt
# owner and group in one call$sudo chown -R comp175user /srv/lib# -R: every file in the folder too
$cat notes.txt
Buy more toner. Reboot lib-web01 Friday.
$cat notes.txt todo.txt
Buy more toner. Reboot lib-web01 Friday.
Email the team about the outage.
$sudo mkdir -p/srv/library-team# -p: no error if exists$sudo chgrp library /srv/library-team# sets the group$sudo chmod 770/srv/library-team# owner+group only$ls-ld/srv/library-team# -d: the dir, not contents
drwxrwx--- 2 comp175user library ... /srv/library-team
Return to Admin: exit
comp175user isn't a sudoer
exit returns to your shell
Admins run sudo, not members
Check with groups or sudo -l
⚠️ A regular team member should not be added to sudoers just to fix this.
Return to Admin: exit
$sudo bash scripts/set-wsl-hostname.sh vm-ubuntu
comp175user is not in the sudoers file.
$exit$groups
your-username sudo$groups comp175user
comp175user library
Can Two VMs Talk?
Yes, if they share a network
Plain NAT isolates each VM
Test first: ping, then ssh
Word Origin: "ssh"
Install & Start sshd
openssh-server provides sshd
WSL has no systemd by default
service ssh start, each boot
⚠️ sshd does not restart on its own after wsl --shutdown.
Install & Start sshd
$sudo apt install -y openssh-server
$sudo service ssh start
$sudo service ssh status
ssh start/running, process 1842
Find lib-web01's IP
Every VM gets its own IP
Yours will differ, that's OK
Type the hostname command
Find lib-web01's IP
$hostname-I172.20.145.10
Same IP on Two VMs?
Same IP = a real conflict
Goes to whichever VM replies
Flaky ping, wrong host reached
Why They Share the Same IP
One shared WSL2 VM
All distros, one virtual NIC
Same IP, every time
Not the same as the host's IP
⚠️ ssh still works, but only one distro can hold a port at once.
⚠️ WSL distros are not separate VMs like VirtualBox creates.
How to Tell Them Apart
hostname is shared by default
Check /etc/os-release instead
cat it, look for the ID line
⚠️ Even the hostname matches the Windows PC by default.
How to Tell Them Apart
$cat/etc/os-release | grep^ID=
ID=kali
Give a Distro Its Own Name
hostname: yes, run a script
IP: still shared, one NIC
True per-VM IPs need real VMs
⚠️ Only the hostname can be made unique; the IP still can't.
Blue = shareable, per FHS's own example table (Ch. 2): /usr, /opt
Static vs. Variable
Static: binaries, libraries
Only admin changes them
Variable: changes on its own
🔧 Admin task: Tells an admin which directories are safe to put on read-only or cheaper/slower storage.
🎓 Design rationale: Why does the static/variable split matter for hardware, not just organization? Static data can physically live on read-only media (a burned disc, a read-only NFS mount) -- variable data cannot. The split isn't just tidiness; it constrains what storage is even usable.
Blue = /usr and /var, under opposite backup/mount policy (Ch. 2 Rationale)
Questions?
The Root Filesystem
Purpose of the Root FS
Boots, restores, repairs it
/usr, /opt, /var can move
Root itself must stay put
🔧 Admin task: Tells an admin exactly what a minimal rescue/recovery partition must include.
🎓 Design rationale: Why must / stay small even with plenty of disk to spare? A corrupted root partition is a far bigger problem than a corrupted data partition -- keeping it minimal limits how much can go wrong in the one place the whole boot depends on.
🔧 Admin task: Because it's guaranteed plain-text, an admin can always git-diff or grep /etc safely to audit config drift.
🎓 Design rationale: Why can't /etc contain binaries? Config files there must be readable and diffable by tools (and by an admin's own eyes) before any package manager has verified binary integrity -- a binary hiding in /etc would defeat the entire point of the directory.
🔧 Admin task: Tells an admin where to find a locked-out user's files vs. the root account's own history and crontab.
🎓 Design rationale: Why is /home optional, not required? Because its real layout varies too much across deployments (NFS-mounted, subdivided by department, or absent on an embedded system) for FHS to mandate one fixed path -- so it stays a strong default, not a hard rule.
Blue = dot-prefixed entries per FHS Sec. 3.8.2; docs is not one
/opt: Add-On Software
Big 3rd-party apps live here
Own tree: /opt/<package>
Never scattered into /usr
🔧 Admin task: This is the first place an admin checks (or cleans up) when auditing third-party software installs.
🎓 Design rationale: Why does FHS require a registered provider name for /opt subdirs? To prevent collisions -- if two unrelated vendors both name their tree /opt/tools, one silently overwrites the other; a registered (often reverse-DNS-style) name guarantees it's unique.
Blue = /media, /mnt, FHS's two mount-point directories (Sec. 3.11.1, 3.12.1)
/run: What's Happening Now
Data since the last boot
Cleared every time it boots
Replaces old /var/run PIDs
🔧 Admin task: After a crashed daemon, an admin checks /run for a stale PID file -- and it's always safe to clear on reboot.
🎓 Design rationale: Why did FHS introduce /run instead of just keeping /var/run? Because /var might not be mounted yet very early in boot, but PID/socket data is needed before that -- /run is its own tmpfs directly on /, so it's guaranteed available from the earliest boot stage.
Blue = /run, holding data since the current boot (FHS Sec. 3.15.1)
Questions?
The /usr Hierarchy
/usr: Shareable, Read-Only
Same /usr on many machines
Must never be written to
Host data lives elsewhere
🔧 Admin task: Confirms it's safe practice to mount /usr read-only (mount -o remount,ro /usr) on a production server.
🎓 Design rationale: Why must /usr be read-only, not just 'usually is'? Because it's often mounted from one shared NFS server onto many clients at once -- a write from any one client would corrupt or race against every other client reading that same tree simultaneously.
🔧 Admin task: ./configure --prefix=/usr/local is the correct install target for anything an admin compiles by hand.
🎓 Design rationale: Why must locally-installed software avoid /usr specifically, not just prefer /usr/local? A package manager tracks and may remove anything it believes it owns under /usr -- a hand-installed file there risks silent deletion on the next system upgrade.
🔧 Admin task: Never hand-edit files under /var/lib; a service's own tooling owns that data. /var/mail/<user> is the real mailbox.
🎓 Design rationale: Why is a mailbox one flat file, not a folder of messages? FHS mandates the classic UNIX mbox format for compatibility with decades of existing mail tooling -- a maildir-style folder tree is a newer alternative some servers use, but it's not what FHS itself defines.
Blue = /usr, /var, under contrasting backup priority (Sec. 5.1 Rationale)
Questions?
Linux-Specific Rules
/proc & /sys: Virtual Trees
Not real files on disk
/proc: process + kernel info
/sys: devices and drivers
🔧 Admin task: cat /proc/cpuinfo or /proc/meminfo gives live diagnostics with zero extra tools to install.
🎓 Design rationale: Why does Linux have both /proc and /sys? /proc came first (process/kernel info, somewhat unstructured over time); /sys was added later specifically to expose device and driver data in a clean, versioned, machine-parseable hierarchy /proc had never enforced.
$sudo mkdir -p/srv/library# -p also creates missing parent dirs
Step 2: Check Who Owns It
New folders start as root
-d: the dir, not contents
Not usable by you yet
$ ls -ld /srv/library
drwxr-xr-x 2 root root 4096 /srv/library
# 2 = parent's entry for it, plus its own "."
# not depth from /: every new dir starts at 2
# +1 for each subdir it holds (that subdir's "..")
# 4096 = the entry list's size (4096 bytes, 4 KiB)
# x on a folder = you may cd into it
Step 2: Check Who Owns It
$ls-ld/srv/librarydrwxr-xr-x2 root root 4096/srv/library# 2 = parent's entry for it, plus its own "."# not depth from /: every new dir starts at 2# +1 for each subdir it holds (its "..")# 4096 = the entry list's size (4096 bytes, 4 KiB)# x on a folder = you may cd into it
Check: Can You Write Yet?
You made /srv/library
Owner and group are root
You are only "other" here
Answer: other has no w, so writes fail
Step 3: Create the Group
One group for all lib staff
Every staff account joins it
groupadd needs sudo
$ sudo groupadd libstaff
# groupadd makes the group, adds no members
Step 3: Create the Group
$sudo groupadd libstaff
# groupadd makes the group, adds no members
Step 4: Join the Group
-aG appends, never replaces
Log out/in for it to apply
groups confirms membership
$ sudo usermod -aG libstaff $USER
$ groups
libstaff sudo docker
# -a appends; -G alone replaces your groups
# $USER = your username, filled in by the shell
Step 4: Join the Group
$sudo usermod -aG libstaff $USER$groups
libstaff sudo docker
# -a appends; -G alone replaces your groups# $USER = your username, filled in by the shell
Check: Group Not Active
usermod added you to libstaff
Your shell has the old groups
What re-reads your groups?
Answer: group loads at the next login
Roles, Not People
Do not grant users one by one
Grant a role, add users to it
In Linux a group is a role
Blue = the role layer, the one thing you manage
Groups Are the Roles
libstaff: every staff account
cataloging / circ / archives
One person can hold many
Each sub-team is its own group under libstaff
Why RBAC Scales
New hire: add to one group
Role changes: swap one group
Audit = list group members
Blue = RBAC: manage roles, not user-folder pairs
Users, Roles, Permissions
A user is put into roles
A role is a Linux group
Permissions sit on the role
carol holds two roles
Never grant a user a file
Dashed line: one user can hold more than one role
Step 5: Change Group Owner
Recall: chown changes both
chgrp changes just the group
Owner (root) stays the same
$ sudo chgrp libstaff /srv/library
# chgrp changes the group only (chown does both)
Step 5: Change Group Owner
$sudo chgrp libstaff /srv/library# chgrp changes the group only (chown does both)
Answer: nobody gets in; root and the owner can chmod it back
Step 7: Verify With ls -l
Confirm before moving on
Group should now be libstaff
Permissions should read 770
$ ls -ld /srv/library
drwxrwx--- 2 root libstaff 4096 /srv/library
# d = directory
# then owner rwx, group rwx, other ---
# root = owner, libstaff = group
Step 7: Verify With ls -l
$ls-ld/srv/library
drwxrwx--- 2 root libstaff 4096/srv/library# d = directory# then owner rwx, group rwx, other ---# root = owner, libstaff = group
Step 8: Create the File
A real file inside the share
touch only creates it, empty
Everyone in libstaff can use
$ touch /srv/library/catalog.txt
# also bumps the timestamp if it exists
Step 8: Create the File
$touch/srv/library/catalog.txt# also bumps the timestamp if it exists
Check: Which Group?
You ran touch catalog.txt
Files take your primary group
Is that libstaff or staff?
Answer: primary group, not libstaff yet
Step 9: Check Its Metadata
Shows owner, inode, and time
Proves the file truly exists
More detail than ls -l alone
$ stat /srv/library/catalog.txt
Inode: 55210 Links: 1
Access: (0644/-rw-r--r--)
# Links = hard-link count (names on this inode)
# 1 now; ln adds one, a symlink does not
# file is gone only when the last name is removed (count 0)
# 0644 octal = -rw-r--r-- in symbols
Step 9: Check Its Metadata
$stat/srv/library/catalog.txt
Inode: 55210 Links: 1
Access: (0644/-rw-r--r--)
# Links = hard-link count (names on this inode)# 1 now; ln adds one, a symlink does not# file is gone only when the last name is removed (count 0)# 0644 octal = -rw-r--r-- in symbols
Step 10: Identify File Type
Confirms it truly has no data
Not just trusting the name
Not installed by default
$ sudo apt install -y file
$ file /srv/library/catalog.txt
catalog.txt: empty
# -y = say yes to the install prompt
# file checks the bytes, not the name
Step 10: Identify File Type
$sudo apt install -y file
$file/srv/library/catalog.txt
catalog.txt: empty
# -y = say yes to the install prompt# file checks the bytes, not the name
Check: Name vs Content
The name ends in .txt
file read the bytes instead
Why not trust the name?
Answer: a name is a label, not proof
Step 11: Create a Symlink
A shortcut in your own home
Points at the shared file
ls -l shows the -> target
$ ln -s /srv/library/catalog.txt ~/catalog-link.txt
$ ls -l ~/catalog-link.txt
lrwxrwxrwx ... catalog-link.txt -> /srv/library/catalog.txt
# -s = symbolic link: stores a path
# leading l = it is a symlink
Step 11: Create a Symlink
$ln-s/srv/library/catalog.txt~/catalog-link.txt$ls-l~/catalog-link.txtlrwxrwxrwx ... catalog-link.txt -> /srv/library/catalog.txt# -s = symbolic link: stores a path# leading l = it is a symlink
Step 12: Create a Hardlink
A second name, same data
Survives if original deleted
Not a shortcut, real data
$ ln /srv/library/catalog.txt /srv/library/catalog-backup.txt
# no -s = hardlink: same inode, new name
Step 12: Create a Hardlink
$ln/srv/library/catalog.txt/srv/library/catalog-backup.txt# no -s = hardlink: same inode, new name
Check: Delete the Original
A hardlink shares the inode
A symlink stores only a path
You delete catalog.txt
Which one still opens?
Answer: backup opens; the symlink now points at nothing
Step 13: Compare the Inodes
Both list the same number
Proves they share one file
The symlink's number differs
$ ls -li /srv/library/catalog*
55210 ... catalog.txt
55210 ... catalog-backup.txt
# -i shows the inode number first
# same number = the same file on disk
Step 13: Compare the Inodes
$ls-li/srv/library/catalog*55210 ... catalog.txt
55210 ... catalog-backup.txt
# -i shows the inode number first# same number = the same file on disk
Step 14: Check Mount Point
Confirms which disk /srv uses
Same idea as Module 3, Item 1
Look at the Mounted on column
$ df -h /srv
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 20G 13G 6G 69% /
# -h = human sizes (K, M, G)
# Mounted on / : /srv rides the root disk
Step 14: Check Mount Point
$df-h/srv
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 20G 13G 6G 69% /
# -h = human sizes (K, M, G)# Mounted on / : /srv rides the root disk
Check: /srv On What Disk?
df -h /srv shows /dev/sda1
Mounted on column reads /
Is /srv its own disk?
Answer: no: /srv rides on the root disk
Step 15: Diagnose an Error
A classmate reports an error
"Permission denied" error
Check the folder, not the file
$ ls -ld /srv/library
drwx------ 2 root libstaff 4096 /srv/library
# drwx------ : only the owner can touch it
⚠️ Group lost its rwx bits -- someone ran chmod 700 by mistake.
Step 15: Diagnose an Error
$ls-ld/srv/library
drwx------ 2 root libstaff 4096/srv/library# drwx------ : only the owner can touch it
Step 16: Fix Permissions
g+rwx adds back group access
Safer than retyping 770
Practice with symbolic chmod
$ sudo chmod g+rwx /srv/library
$ ls -ld /srv/library
drwxrwx--- 2 root libstaff 4096 /srv/library
# g = group, +rwx = add; owner and other untouched
Step 16: Fix Permissions
$sudo chmod g+rwx /srv/library$ls-ld/srv/library
drwxrwx--- 2 root libstaff 4096/srv/library# g = group, +rwx = add; owner and other untouched
Check: Symbolic vs Numeric
chmod g+rwx added group bits
chmod 770 sets all three roles
When is g+rwx the safer pick?
Answer: g+rwx leaves owner and other alone
Phase 1: What You Built
/srv/library, group libstaff
Mode 770, a real file inside
One symlink, one hardlink
This is your Phase 1 end state
Now Work As a Team
Phase 2: Solve It Together
How Phase 2 Works
Each of you on your own VM
Talk through the approach
Try it, then check the key
Answers follow all 10
Blue = the answer key at the end
Problem 1: New Staff
You were added to libstaff in Phase 1, but this shell opened before that, so writing to /srv/library still fails. Run newgrp libstaff (or log out and back in), then create a file in the share. In one sentence, say why the first attempt failed.
The shell opened before the group was added
Problem 2: Wrong Group
Cataloging made records.txt with group staff, so Circulation cannot edit it. Run sudo chmod g+s /srv/library so new files inherit libstaff, and fix the old file with sudo chgrp libstaff records.txt. Check that a brand-new file now shows group libstaff.
New files inherit the creator primary group
Problem 3: Anyone Deletes
Everyone in libstaff has write on the share, so anyone can delete anyone's file. Add the sticky bit: sudo chmod +t /srv/library. Now try to delete a file a teammate owns — it should be refused. Confirm ls -ld shows drwxrws--T.
Deleting a file needs write on the folder
Problem 4: Legacy Folder
The archives folder predates setgid, so its group is root and new files there miss libstaff. Fix the old files with sudo chgrp -R libstaff /srv/library/archives, then re-apply setgid: sudo chmod g+s /srv/library/archives. Verify with ls -lR that every line reads libstaff.
setgid only affects files made after it was set
Problem 5: Broken Link
~/today.txt is a symlink showing red and "No such file" because its target was renamed. Run ls -l ~/today.txt to see the path it stores, then re-point it: ln -sfn /srv/library/<real-name> ~/today.txt. Confirm cat ~/today.txt works again.
A symlink stores a path string, not the file
Problem 6: Disk Is Full
df -h /srv reads 96% full. Archives made hardlink backups (cheap) but also cp-d some originals (real bytes). Run du -sh * in each folder and ls -li to spot files that share an inode. Report which files are true copies eating the space.
Hardlinks add a name only; copies add real data
Problem 7: Wrong Disk
/srv/library is on the small root disk; a big /data disk is mounted. Write the ordered move: sudo mv /srv/library /data/library, then sudo ln -s /data/library /srv/library so the old path still works. Note which links break (hardlinks) and which survive (symlinks, data).
Inodes are per-filesystem; hardlinks cannot cross a mount
Problem 8: Read a Subdir?
circulation is set to 750 and Archives is in libstaff. Split 750 into owner / group / other and read the group digit (5 = r-x). Answer: can an Archives user cd into circulation and ls it? Can they add a file?
7 = rwx, 5 = r-x, 0 = --- : the group column decides
Problem 9: Root Owns It
policy.txt is -rw-r--r-- owned by root and staff must edit it. Do NOT run chmod 666 (that lets the whole world write). Instead: sudo chgrp libstaff policy.txt then sudo chmod g+w policy.txt. Confirm it ends -rw-rw-r--.
chmod 666 would let the whole world write the policy
Problem 10: Final Audit
Produce one ls -lR /srv/library and explain every line: for each directory and file, say what the mode string grants and to whom (owner, libstaff, other). State clearly what "other" is allowed to do (nothing).
This is the state built across Problems 1 to 9
Answer Key
Answer 1: New Staff
Groups load at login only
newgrp libstaff or re-login
id must list libstaff
Then 770 lets them write
A fresh login re-reads group membership
Answer 2: Wrong Group
Set setgid on the dir
chmod g+s /srv/library
New files inherit libstaff
Old files: chgrp -R libstaff
setgid on a directory forces its group onto new files
Answer 3: Anyone Deletes
Add the sticky bit
chmod +t /srv/library
Only owner or root unlinks
ls shows drwxrws--T
The sticky bit limits deletion to each file owner
Answer 4: Legacy Folder
chgrp -R libstaff archives
chmod -R g+w archives
Re-set setgid on the dir
Verify with ls -lR
Recursive chgrp fixes old files; setgid fixes new ones
Answer 5: Broken Link
Holds a path, not an inode
ln -s new-name ~/today.txt
Or restore the old filename
A hardlink survives a rename
Point the link at the new name, or rename the target back
Answer 6: Disk Is Full
Hardlinks share blocks: ls -li
du counts shared data once
The cp copies are the cost
Delete copies, keep the links
Two copies use twice the blocks; two hardlinks use one set
Answer 7: Wrong Disk
Move dir to /data/library
Leave /srv/library as a link
Hardlinks break: recreate them
Symlinks and data survive
A symlink at the old path keeps every reference working
Answer 8: Read a Subdir?
Group gets r-x on the dir
r lets them ls the names
x lets them cd into it
No w: they cannot add files
Read plus execute on a directory means list and enter, not modify
Answer 9: Root Owns It
sudo chgrp libstaff policy.txt
sudo chmod g+w policy.txt
Now -rw-rw-r--
Other stays read-only
Give the group write through group ownership, never through other
Answer 10: Final Audit
Dirs: drwxrws--T, grp libstaff
s=setgid, T=sticky, no other
Files: -rw-rw----, libstaff
World: no access anywhere
setgid keeps the group, sticky guards deletes, other is shut out
$ touch /tmp/report.txt
$ chmod 640 /tmp/report.txt
# 640 = rw-r----- (group read, others none)
$ getfacl /tmp/report.txt
# no flags: print the file's full ACL
user::rw-
group::r--
other::---
⚠️ Uses /tmp on purpose: WSL's Windows-mounted drives (/mnt/c/...) don't support ACLs at all, wherever else on your system you might try this.
See a File's Full ACL
$touch /tmp/report.txt
$chmod 640 /tmp/report.txt
# 640 = rw-r----- (group read, others none)$getfacl /tmp/report.txt
# no flags: print the file's full ACL
user::rw-
group::r--
other::---
Grant One More Person
-m modifies the ACL
u:name:perms adds a rule
Owner and group untouched
$ setfacl -m u:daemon:rw /tmp/report.txt
# -m modifies the ACL; owner needs no sudo
# daemon: a real account on every Linux box
$ getfacl /tmp/report.txt
user:daemon:rw-
Grant One More Person
$setfacl-m u:daemon:rw /tmp/report.txt
# -m modifies the ACL; owner needs no sudo# daemon: a real account on every Linux box$getfacl /tmp/report.txt
user:daemon:rw-
Without ACL
$ getfacl /tmp/report.txt
# no flags: print the file's full ACL
user::rw-
group::r--
other::---
# daemon has no rule: not in the list
With ACL
$ setfacl -m u:daemon:rw /tmp/report.txt
# -m modifies the ACL; owner needs no sudo
$ getfacl /tmp/report.txt
user::rw-
group::r--
user:daemon:rw-
other::---
# daemon now has its own explicit rule
⚠️ ALLOWED here isn't final: MAC still checks afterward and can still deny it.
Without ACL
$getfacl /tmp/report.txt
# no flags: print the file's full ACL
user::rw-
group::r--
other::---
# daemon has no rule: not in the list
With ACL
$setfacl-m u:daemon:rw /tmp/report.txt
# -m modifies the ACL; owner needs no sudo$getfacl /tmp/report.txt
user::rw-
group::r--
user:daemon:rw-
other::---
# daemon now has its own explicit rule
Without ACL
$ setfacl -x u:daemon /tmp/report.txt
# -x removes daemon's entry, if any
$ sudo -u daemon test -r /tmp/report.txt \
&& echo OK || echo DENIED
# -u: run it as daemon (more on sudo soon)
# test -r: exit 0 if readable, nonzero if not
DENIED
With ACL
$ setfacl -m u:daemon:rw /tmp/report.txt
# -m grants daemon read+write
$ sudo -u daemon test -r /tmp/report.txt \
&& echo OK || echo DENIED
# test -r: exit 0 if readable, nonzero if not
OK
⚠️ Uses /tmp, not your home folder: a private home directory (mode 750) blocks daemon before it ever reaches the file's own ACL.
Without ACL
$setfacl-x u:daemon /tmp/report.txt
# -x removes daemon's entry, if any$sudo-u daemon test-r /tmp/report.txt \
&& echo OK || echo DENIED
# -u: run it as daemon (more on sudo soon)# test -r: exit 0 if readable, nonzero if notDENIED
With ACL
$setfacl-m u:daemon:rw /tmp/report.txt
# -m grants daemon read+write$sudo-u daemon test-r /tmp/report.txt \
&& echo OK || echo DENIED
# test -r: exit 0 if readable, nonzero if notOK
$ setfacl -m m::r-- /tmp/report.txt
# narrows the mask; daemon's entry is unchanged
$ getfacl /tmp/report.txt
user:daemon:rw- #effective:r--
mask::r--
# daemon still SAYS rw-, but write is masked out
When the Mask Contradicts
$setfacl-m m::r-- /tmp/report.txt
# narrows the mask; daemon's entry is unchanged$getfacl /tmp/report.txt
user:daemon:rw- #effective:r--mask::r--# daemon still SAYS rw-, but write is masked out
chmod Changes the Mask Too
chmod g+w hits the mask
Not the group:: line
Surprising once ACLs exist
$ chmod g+w /tmp/report.txt
# looks like it changes the group, but...
$ getfacl /tmp/report.txt
group::r--
mask::rw-
# mask moved, group:: line did not
⚠️ Once a file has an ACL, plain chmod on the group bits edits the mask, not group::.
chmod Changes the Mask Too
$chmod g+w /tmp/report.txt
# looks like it changes the group, but...$getfacl /tmp/report.txt
group::r--
mask::rw-# mask moved, group:: line did not
Questions?
Users, Groups & sudo
Why Not Log In as root?
root can do anything at all
One mistake, no undo
sudo logs who did what
Who Am I Right Now?
Prints your effective user
Useful inside scripts
Differs once you sudo
$ whoami
# prints the currently logged-in username
alice
Who Am I Right Now?
$whoami# prints the currently logged-in usernamealice
Logged In as root
$ whoami
root
# every command now runs as root
# nothing records who you really are
Using sudo Instead
$ whoami
alice
$ sudo whoami
root
# sudo logs this command's use
# you're alice again right after
⚠️ Root leaves no name behind: sudo's log is what proves who ran it.
Logged In as root
$whoamiroot# every command now runs as root# nothing records who you really are
Using sudo Instead
$whoamialice$sudowhoamiroot# sudo logs this command's use# you're alice again right after
Switching Identity: su
su alone targets root
su - name loads their shell
Needs that user's password
$ sudo useradd -m registrar_admin
# -m also creates their home directory
$ sudo passwd registrar_admin
# sets their password (prompts interactively)
$ su - registrar_admin
# - = login shell (loads registrar_admin's own env)
Password:
$ exit
Switching Identity: su
$sudouseradd-mregistrar_admin# -m also creates their home directory$sudopasswdregistrar_admin# sets their password (prompts interactively)$su-registrar_admin# - = login shell (loads registrar_admin's own env)Password:$exit
sudo -i: A Root Shell
Full shell, like su -
Uses YOUR password though
sudo logs who started it
$ sudo -i
# -i starts a full root login shell
root@host:~# whoami
root
root@host:~# exit
# back to alice, your own prompt
⚠️ Commands typed inside aren't individually logged; exit as soon as you're done.
sudo -i: A Root Shell
$sudo-i# -i starts a full root login shellroot@host:~#whoamirootroot@host:~#exit# back to alice, your own prompt
Reading a sudoers Line
Who: a user or %group
Where: ALL hosts
As whom, running what
Editing sudoers Safely
visudo locks the file
Checks syntax before saving
Never edit sudoers directly
$ sudo groupadd registrar
# creates the group this rule targets
$ sudo visudo
# opens /etc/sudoers safely with syntax checking
%registrar ALL=(root) NOPASSWD: \
/usr/local/bin/backup.sh
# %group ALL=(role) NOPASSWD: cmd -- no password prompt
Editing sudoers Safely
$sudogroupadd registrar
# creates the group this rule targets$sudovisudo# opens /etc/sudoers safely with syntax checking%registrar ALL=(root) NOPASSWD: \
/usr/local/bin/backup.sh
# %group ALL=(role) NOPASSWD: cmd -- no password prompt
sudo
$ sudo whoami
root
# runs ONE command as root
visudo
$ sudo visudo
# opens /etc/sudoers itself, safely
⚠️ A broken /etc/sudoers can lock out ALL sudo access; visudo checks syntax before saving so that can't happen.
sudo
$sudowhoamiroot# runs ONE command as root
visudo
$sudovisudo# opens /etc/sudoers itself, safely
What Can I Run?
Lists your sudo rules
Shows allowed commands
Good first debugging step
$ sudo -l
# -l lists what commands you're allowed to run
User alice may run:
(root) /usr/local/bin/backup.sh
What Can I Run?
$sudo-l# -l lists what commands you're allowed to runUser alice may run:
(root) /usr/local/bin/backup.sh
Real sudo -l Output
Defaults: config, not a grant
(ALL : ALL) ALL = full access
Common on your own dev VM
$ sudo -l
Matching Defaults entries for alice:
secure_path=/usr/sbin:/usr/bin:/sbin:/bin
User alice may run the following commands:
(ALL : ALL) ALL
# any user, any group, any command
Real sudo -l Output
$sudo-lMatching Defaults entries for alice:
secure_path=/usr/sbin:/usr/bin:/sbin:/bin
User alice may run the following commands:(ALL : ALL) ALL# any user, any group, any command
On the Registrar Server
$ sudo -l
User alice may run:
(root) /usr/local/bin/backup.sh
# one script, nothing else
On Your Own Dev VM
$ sudo -l
User alice may run the following commands:
(ALL : ALL) ALL
# every command, as anyone
⚠️ Scope matters: the same person can hold a narrow grant on one box and full access on another.
On the Registrar Server
$sudo-lUser alice may run:
(root) /usr/local/bin/backup.sh
# one script, nothing else
On Your Own Dev VM
$sudo-lUser alice may run the following commands:(ALL : ALL) ALL# every command, as anyone
Word Origin: "sudo"
su
already meant "switch user"
do
"do" this one thing as them
Read aloud as "superuser do": run one command with another user's privilege.
su -
$ su - registrar_admin
Password:
$ whoami
registrar_admin
$ exit
# stays as registrar_admin until exit
# needs registrar_admin's password
sudo
$ sudo whoami
root
# runs just this one command
# needs YOUR OWN password instead
su -
$su-registrar_adminPassword:$whoamiregistrar_admin$exit# stays as registrar_admin until exit# needs registrar_admin's password
sudo
$sudowhoamiroot# runs just this one command# needs YOUR OWN password instead
Check: sudo vs. su
sudo: one command, logged
su: a whole new shell
Which fits a backup script?
Answer: sudo; it runs just that script and records who ran it
Running as Someone Else
-u picks the target user
Still needs a sudoers rule
Not always root
$ sudo -u www-data whoami
# -u runs the command as another user (www-data)
www-data
Running as Someone Else
$sudo-u www-data whoami# -u runs the command as another user (www-data)www-data
Managing Group Membership
-a adds, -d removes
Cleaner than usermod -aG
Confirm with groups
$ sudo gpasswd -a alice registrar
# -a adds alice to the registrar group
$ groups alice
alice : registrar
Managing Group Membership
$sudogpasswd-aalice registrar
# -a adds alice to the registrar group$groups alice
alice : registrar
usermod -aG
$ sudo usermod -aG registrar alice
# -aG appends; omit -a and it WIPES
# alice's other groups if you forget it
gpasswd -a
$ sudo gpasswd -a alice registrar
# -a only ever adds this one group
$ sudo gpasswd -d alice registrar
# -d removes it just as safely
⚠️ Forgetting -a on usermod -aG can wipe every other group alice already had.
usermod -aG
$sudousermod-aG registrar alice# -aG appends; omit -a and it WIPES# alice's other groups if you forget it
gpasswd -a
$sudogpasswd-aalice registrar
# -a only ever adds this one group$sudogpasswd-dalice registrar
# -d removes it just as safely
Questions?
Questions?
Why Audit?
Prevention can still fail
Logs show who did what
Append-only, hard to change
Needed for compliance
The AAA Model, Revisited
Authentication: who you are
Authorization: what you may do
Accounting: what you did
Who Requires Audit Logs?
FERPA: student records
PCI-DSS: payment data
NIST 800-53: federal systems
Frameworks That Require It
Each names what to log
None specifies the tool
inotify satisfies file logging
Framework
Protects
FERPA
Student education records
PCI-DSS
Card payment data
NIST SP 800-53
Federal information systems
Who's On Right Now?
Shows logged-in sessions
Works on Kali and Ubuntu
No install needed
$ who
# no flags: shows who is logged in right now
alice pts/0 2026-09-12 09:15
Who's On Right Now?
$who# no flags: shows who is logged in right nowalice pts/0 2026-09-12 09:15
What Is Everyone Doing?
Adds idle time and load
WHAT column shows the shell
Good first audit glance
$ w
# no flags: who's on, plus load and idle time
09:44 up 1:10, 1 user, load avg: 0.31
USER TTY LOGIN@ IDLE WHAT
alice pts/0 09:15 0.02s -bash
What Is Everyone Doing?
$w# no flags: who's on, plus load and idle time
09:44 up 1:10, 1 user, load avg: 0.31
USER TTY LOGIN@ IDLE WHAT
alice pts/0 09:15 0.02s -bash
Word Origin: "Audit"
audire
Latin: to hear
-it
one who listens, examines
An auditor originally "heard" accounts read aloud; inotify listens for file events instead.
Check: What's in the Log?
Who did it
What they did, and when
Not: their plaintext password
Answer: who/what/when belong in the log; secrets like passwords never do
$ sudo gpasswd -a $(whoami) registrar
# adds you to the group so you can watch it
$ sudo apt install -y util-linux-extra
# newgrp isn't installed on every distro
$ newgrp registrar
# newgrp reloads this shell; groupadd made it
$ sudo mkdir -p /srv/registrar
$ sudo chgrp registrar /srv/registrar
$ sudo chmod 2770 /srv/registrar
# 2770 = rwxrws--- (registrar group can write)
$ inotifywait -m -e create,modify \
/srv/registrar >> /tmp/registrar-watch.log &
Step 4: Watch the Folder
$sudogpasswd-a $(whoami) registrar
# adds you to the group so you can watch it$sudoaptinstall-y util-linux-extra
$newgrp registrar
# newgrp reloads this shell; groupadd made it$sudomkdir-p /srv/registrar
$sudochgrp registrar /srv/registrar
$sudochmod 2770 /srv/registrar
$inotifywait-m-e create,modify \
/srv/registrar >> /tmp/registrar-watch.log &
Does the Rule Really Work?
An untested rule is a guess
Trigger it, search the log
The key ties event to rule
Step 5: Append, No Editor
No editor touches this file
Creates the file if missing
Counts as a modify event
$ echo "New patron: J. Smith" \
>> /srv/registrar/test.txt
Step 5: Append, No Editor
$ echo "New patron: J. Smith" \
>> /srv/registrar/test.txt# appends; no editor ever opened
Step 6: Trigger and Confirm
Step 5 already made the edit
Search the log for its name
You should see the modify
$ grep test.txt /tmp/registrar-watch.log
# reuses grep from earlier: no new command
Step 6: Trigger and Confirm
$grep test.txt /tmp/registrar-watch.log
# finds the echo append from Step 5
Check: Who Can Run It?
Group registrar has the rule
bob is not in that group
Can bob run the script?
Answer: no; only members of registrar inherit the sudoers rule
Did It Actually Stick?
chmod ran, but did it apply?
getfacl shows the real state
Compare it to what you meant
Step 7: Verify with ACLs
Confirm the group can write
getfacl shows every rule
Compare to your sudoers line
$ getfacl /srv/registrar
# no flags: print the directory's full ACL
group::rwx
Step 7: Verify with ACLs
$getfacl /srv/registrar
# no flags: print the directory's full ACL
group::rwx
$sudo apt install -y git
# not installed on every minimal image$git clone https://github.com/SE4CPS/2026-COMP-175.git# pulls the real, synthetic sample files
$sudomkdir-p/srv/patient-records# the tree the sample data copies into$sudocp-r \
~/2026-COMP-175/modules/module-4/lab2/sample-data/* \
/srv/patient-records/# record.txt, today/invoice.txt, notes.txt$sudochown-R $(whoami) /srv/patient-records# you own it now; setfacl below needs no sudo
$sudogroupadd physicians
# creates the physicians group$sudogroupadd nurses
# creates the nurses group$sudogroupadd billing
# creates the billing group$sudogroupadd admin
# creates the admin group$getent group nurses
# confirms the group now exists
$setfacl-m u:daemon:r-- \
/srv/patient-records/record.txt# -m modifies; u:daemon:r-- grants read only$getfacl/srv/patient-records/record.txt# confirms the new rule is really there
Problem 5: New Nurse
Dana joins the nursing staff
Needs today's patients only
How would you address this?
Options: New Nurse
Pick the one that fixes it
Some look tempting, but wrong
Which is safest here?
The Fix: New Nurse
B is correct: join the group
A opens it to everyone
C copies data out, no access
$ sudo useradd -m dana
$ sudo gpasswd -a dana nurses
The Fix: New Nurse
$sudouseradd-m dana
# creates dana's account first$sudogpasswd-a dana nurses
# -a adds dana to the nurses group$groups dana
# confirm the membership took
$sudouseradd-m morgan
# creates morgan's account first$setfacl-m u:morgan:rw \
/srv/patient-records/today/invoice.txt# -m modifies the ACL; adds morgan$getfacl/srv/patient-records/today/invoice.txt# confirm the new rule is there
$inotifywait-m-r-e modify \
--timefmt'%Y-%m-%d %H:%M:%S' \
--format'%T %w%f %e' \
/srv/patient-records >> /tmp/watch.log &
# -m keeps watching; -r covers subfolders# --format adds a real timestamp per line# log lives outside the watched folder
Problem 8: Add a Note
Add a note, no editor allowed
Content still needs updating
How would you address this?
Options: Add a Note
Pick the one that fixes it
Some look tempting, but wrong
Which is safest here?
The Fix: Add a Note
B is correct: appends, no edit
A opens an editor: forbidden
C destroys the original file
$ echo "Called in sick, back Monday" \
>> /srv/patient-records/today/notes.txt
The Fix: Add a Note
$ echo "Called in sick, back Monday" \
>> /srv/patient-records/today/notes.txt# >> appends; no editor ever opened
Problem 9: Try grep
Need to search inside a log
grep finds lines by text
How would you address this?
Options: Try grep
Pick the one that fixes it
Some look tempting, but wrong
Which is safest here?
The Fix: Try grep
A is correct: pattern first
B: arguments are reversed
C shows everything, unfiltered
$ grep notes.txt /tmp/watch.log
The Fix: Try grep
$grep notes.txt /tmp/watch.log# searches for that text inside the log# pattern first, file to search second
Problem 10: Spot the Change
A note was added after hours
Confirm it, don't guess
How would you address this?
Options: Spot the Change
Pick the one that fixes it
Some look tempting, but wrong
Which is safest here?
The Fix: Spot the Change
B is correct: confirms the log
A shows content, not a change
C: inotify isn't a service
$ grep notes.txt /tmp/watch.log
The Fix: Spot the Change
$grep notes.txt /tmp/watch.log# confirms the After Hours watch caught it# proof the change was logged, not guessed
Problem 11: Last Day
Their last day is today
Access must end immediately
How would you address this?
Options: Last Day
Pick the one that fixes it
Some look tempting, but wrong
Which is safest here?
The Fix: Last Day
B is correct: leaves the group
A blocks login, not access
C deletes the wrong thing
$ sudo gpasswd -d dana nurses
$ groups dana
$ setfacl -x u:dana \
/srv/patient-records/today/invoice.txt
The Fix: Last Day
$sudogpasswd-d dana nurses
# -d removes dana from nurses$groups dana
# confirm the group is gone$setfacl-x u:dana \
/srv/patient-records/today/invoice.txt# also revoke any personal ACL rule
$setfacl-m m::r-- \
/srv/patient-records/record.txt# caps every named/group entry at r--$getfacl/srv/patient-records/record.txt# doctor's entry now shows #effective:r--
Problem 14: Which Group?
A nurse says access is broken
Don't guess, check first
How would you address this?
Options: Which Group?
Pick the one that fixes it
Some look tempting, but wrong
Which is safest here?
The Fix: Which Group?
B is correct: diagnose first
A re-adds before checking
C is a blind, risky guess
$ id dana
The Fix: Which Group?
$id dana
# lists every group dana belongs to# compare against what today/ requires
Problem 15: Locked Out
Dana forgot their password
No sudo needed to fix this
How would you address this?
Options: Locked Out
Pick the one that fixes it
Some look tempting, but wrong
Which is safest here?
The Fix: Locked Out
B is correct: resets it
A grants sudo, unrelated
C: the account already exists
$ sudo passwd dana
The Fix: Locked Out
$sudopasswd dana
# resets their password only# no group or ACL change at all
Problem 16: Two Roles
Alex covers nursing, billing
Keep both sets of access
How would you address this?
Options: Two Roles
Pick the one that fixes it
Some look tempting, but wrong
Which is safest here?
The Fix: Two Roles
A is correct: adds the second
B: already in nurses, no-op
C: -G alone drops nurses!
$ sudo useradd -m alex
$ sudo gpasswd -a alex nurses
$ sudo gpasswd -a alex billing
The Fix: Two Roles
$sudouseradd-m alex
# creates alex's account first$sudogpasswd-a alex nurses
# alex already covers nursing duty$sudogpasswd-a alex billing
# -a only adds; nurses is kept too
Problem 17: Wrong Owner
A file was created as root
Owner should be alex instead
How would you address this?
Options: Wrong Owner
Pick the one that fixes it
Some look tempting, but wrong
Which is safest here?
The Fix: Wrong Owner
A is correct: fixes owner
B changes mode, not owner
C only changes the group
$ sudo chown alex \
/srv/patient-records/record.txt
The Fix: Wrong Owner
$sudochown alex \
/srv/patient-records/record.txt# chown changes the owner field only$ls-l/srv/patient-records/record.txt# confirm alex now owns the file
$ls-l/srv/patient-records/today/shortcut# l at the start means it's a symlink$readlink/srv/patient-records/today/shortcut# shows exactly where the link points# outside patient-records: needs fixing$rm/srv/patient-records/today/shortcut# removes only the broken link itself$ln-s/srv/patient-records/today/notes.txt \
/srv/patient-records/today/shortcut# relinks it to a real file inside
$sudomkdir-p/srv/patient-records/billing# the shared billing folder itself$chmod g-w /srv/patient-records/billing
# group can no longer write by default$setfacl-m u:morgan:rw \
/srv/patient-records/today/invoice.txt# write granted per file, not per folder
Problem 20: Who's Online?
About to make a risky change
Check who's active first
How would you address this?
Options: Who's Online?
Pick the one that fixes it
Some look tempting, but wrong
Which is safest here?
The Fix: Who's Online?
A is correct: shows who's on
B reboots on active users
C: risky, unaware of who's on
$ w
The Fix: Who's Online?
$w# shows who is on, and what they run# wait until their session is done
$nohup inotifywait -m-r-e modify \
--timefmt'%Y-%m-%d %H:%M:%S' \
--format'%T %w%f %e' \
/srv/patient-records >> /tmp/watch.log &
# nohup: ignore the hangup on logout$disown# detaches it from this shell fully
Problem 23: New Admin
A new admin needs full setup
Account, password, right group
How would you address this?
Options: New Admin
Pick the one that fixes it
Some look tempting, but wrong
Which is safest here?
The Fix: New Admin
A is correct: all in one
B alone: no account made yet
C grants full sudo: too broad
$ sudo useradd -m -G admin ravi
$ sudo passwd ravi
The Fix: New Admin
$sudouseradd-m-G admin ravi
# -m home dir; -G admin group at once$sudopasswd ravi
# sets ravi's own password$groups ravi
# confirm admin membership took
$sudoss-tlnp | grep :22
# lists listening ports; empty = not open$sudoufw allow 22/tcp
# if it was closed, this opens just port 22$hostname-I# reveals this VM's own IP address
Problem 25: Connect via SSH
No shared admin account exists
Use YOUR OWN login instead
How would you address this?
Options: Connect via SSH
Pick the one that fixes it
Some look tempting, but wrong
Which is safest here?
The Fix: Connect via SSH
B is correct: nothing skipped
A: bare name won't resolve
C: root login usually off
$ sudo passwd $(whoami)
$ echo "<VM-IP> clinic-records" \
| sudo tee -a /etc/hosts
$ ssh $(whoami)@clinic-records
The Fix: Connect via SSH
$sudopasswd $(whoami)
# sets a password for YOUR OWN account$ echo "<VM-IP> clinic-records" \
| sudotee-a /etc/hosts
# <VM-IP>: the address from Port Open?$ssh $(whoami)@clinic-records
# run this from Kali, not from Ubuntu
Problem 26: Remote New Hire
Now connected in from Kali
Same job, new access method
How would you address this?
Options: Remote New Hire
Pick the one that fixes it
Some look tempting, but wrong
Which is safest here?
The Fix: Remote New Hire
B is correct: same commands
A creates no account at all
C: never share one account
$ sudo useradd -m newhire
$ sudo passwd newhire
The Fix: Remote New Hire
$sudouseradd-m newhire
# same command, whether local or ssh$sudopasswd newhire
# sets their password (prompts you)
Problem 27: Access Report
Compliance wants a full report
Every rule, every user
How would you address this?
Options: Access Report
Pick the one that fixes it
Some look tempting, but wrong
Which is safest here?
The Fix: Access Report
A checks every real source
B only shows base permissions
C: self-reports aren't proof
$ sudo -l -U morgan
$ getfacl /srv/patient-records
$ groups morgan dana alex
The Fix: Access Report
$sudo-l-U morgan
# -U checks another user's sudo rules$getfacl /srv/patient-records
# every ACL rule on the tree, at once$groups morgan dana alex
# group membership for the report
Problem 28: Root Bypassed
Root wrote the file directly
ACLs never stopped it at all
How would you address this?
Options: Root Bypassed
Pick the one that fixes it
Some look tempting, but wrong
Which is safest here?
The Fix: Root Bypassed
B is correct: DAC exempts root
A: root ignores ACLs too
C: root ignores chmod as well
$ stat /srv/patient-records/record.txt
The Fix: Root Bypassed
$stat/srv/patient-records/record.txt# Modify: shows it really did change$ls-l/srv/patient-records/record.txt# owner unchanged; root wrote through it# DAC (chmod/ACL) never governs root# MAC is the only real answer here
Problem 29: Incident Report
Suspicious write, after hours
Find who, confirm, then act
How would you address this?
Options: Incident Report
Pick the one that fixes it
Some look tempting, but wrong
Which is safest here?
The Fix: Incident Report
B is correct: narrows suspects
A: the log has no username
C fixes nothing; recurs
$ grep invoice.txt /tmp/watch.log
$ getfacl /srv/patient-records/today
$ groups morgan dana alex
The Fix: Incident Report
$grep invoice.txt /tmp/watch.log# confirms WHEN, never WHO$getfacl /srv/patient-records/today
# lists everyone with real access$groups morgan dana alex
# cross-check who is in each group# narrow the suspects, then revoke
Problem 30: Back on Kali
Clinic Records work is done
Confirm you're truly local
How would you address this?
Options: Back on Kali
Pick the one that fixes it
Some look tempting, but wrong
Which is safest here?
The Fix: Back on Kali
A is correct: clean exit
B leaves it hanging, not clean
C shuts down the clinic's VM
$ exit
$ hostname
The Fix: Back on Kali
$exit# leaves the SSH session, back to Kali$hostname# confirms you're on kali, not clinic-records
$scp $(whoami)@clinic-records:/tmp/watch.log \
~/incident-watch.log# copies the file itself over ssh# same login you already set up earlier
Deliverables
Answers to all 31 problems
Real gpasswd/setfacl output
No editor ever touched data
Questions?
Practice Lab Part 3
Pair Up: User & Admin
One types User, one Admin
User asks; Admin explains
Click reveals the real answer
Problem 1: How Many Roles?
User: "How many roles do we have on this system?"
Admin: Four: physicians, nurses, billing, and admin. Each one is its own Linux group.
Problem 2: Nurses in today/
User: "What can the nurses role actually do in today/?"
Admin: Dana's account is in the nurses group, so anyone in that group can read and write inside today/ per its group permissions.
Problem 3: ACL vs. Group
User: "Why did morgan get an ACL instead of joining a group?"
Admin: Morgan only needed one file, today/invoice.txt. A per-file ACL grants exactly that without giving access to everything else billing can see.
Problem 4: Who Can Read It?
User: "Who can currently read record.txt?"
Admin: Run getfacl /srv/patient-records/record.txt. It lists the owner, group, and any extra ACL entries. Don't guess; check.
Problem 5: Dana's Access?
User: "Does dana still have access to invoice.txt?"
Admin: No. Last Day removed her from nurses and revoked her personal ACL entry on today/invoice.txt.
Problem 6: Check Who's On
User: "Can you tell who's logged in right now?"
Admin: Yes: w shows every logged-in user and what they're currently running.
Problem 7: Still Open?
User: "Is port 22 still open on this VM?"
Admin: Check with sudo ss -tlnp | grep :22. If it's closed, sudo ufw allow 22/tcp opens it.
Problem 8: Why No Editors?
User: "Why can't I just open a file in an editor?"
Admin: House rule for this VM: every change has to be a logged, auditable command. An editor session isn't tied to one specific action in the log.
Problem 9: Just chmod 777?
User: "Wouldn't chmod 777 just fix any access problem?"
Admin: No. That opens the file to literally everyone, including people who should never touch patient records. Use a narrow ACL grant instead.
Problem 10: Why No Access?
User: "Why can't I access the system at all?"
Admin: A few real possibilities: your account doesn't exist yet, you're not in the right group, or, if it's root's own doing, DAC just doesn't apply to root. Check groups and id first, then getfacl, before assuming it's broken.
Questions?
Practice Lab Part 4
Real Questions, Verified
Real sysadmins, real questions
From Stack Exchange, not us
Checked before adding them
Problem 1: chmod vs. ACL
User: "What's the actual difference between chmod and ACLs?"
Admin: Neither replaces the other; both apply to the same file at once. POSIX permissions (chmod) only cover owner, group, and everyone else; ACLs let you grant extra individual users or groups beyond that base set.
Admin: It would break the filesystem's tree structure: there'd be no way to tell an original directory from a link to it, which risks creating loops that crash tools like fsck.
User: "What's the real difference between apt-get and aptitude?"
Admin: aptitude adds a terminal menu UI on top of very similar core behavior. Both track which packages you installed manually vs. as dependencies, for cleaner auto-removal later.
Answer: the running ssh; the file is only the program
Questions?
Watching Processes
List Processes: ps
ps aux: every user, full list
A snapshot from THAT INSTANT
Pipe to grep to filter
$ ps aux
# every user, one line per process
USER PID %CPU STAT COMMAND
root 1 0.0 Ss /sbin/init
student 812 0.0 Ss -bash
student 901 0.0 R+ ps aux
# columns trimmed to fit the slide
$ ps aux | grep sshd
# filter: only the line(s) you want
# grep itself briefly shows up too
List Processes: ps
$ps aux
# every user, one line per process
USER PID %CPU STAT COMMAND
root 1 0.0 Ss /sbin/init
student 812 0.0 Ss -bash
student 901 0.0 R+ ps aux
# columns trimmed to fit the slide$ps aux | grepsshd# filter: only the line(s) you want# grep itself briefly shows up too
More Examples: ps
Filter by service name
See who is the parent
Repeat it automatically
$ ps aux | grep sshd
# one running service, by name
$ ps -ef --forest
# --forest: shows parent -> child
# tree, e.g. sshd starting a shell
$ watch -n 2 ps aux
# watch: reruns ps every 2 seconds
# Ctrl+C to stop watching
More Examples: ps
$ps aux | grepsshd# one running service, by name$ps-ef--forest# --forest: shows parent -> child# tree, e.g. sshd starting a shell$watch-n2ps aux
# watch: reruns ps every 2 seconds# Ctrl+C to stop watching
Use Case: ps
Is the service running at all?
Who owns it, and since when?
Scripts and audits use ps too
Use Case: Incident Response
A strange process is running
Confirm it exists, then look
Don't kill it before you know
Reading ps aux
One line per process
STAT holds the state code
Find yours by the USER column
Live View: top
top redraws every 3 seconds
q quits, P sorts by CPU
M sorts by memory
$ top
# stays open; q to quit
top - 19:08:23 up 1 day, 1 user
Tasks: 31 total, 1 running
%Cpu(s): 0.7 us, 98.6 id
MiB Mem : 7768.6 total
PID USER %CPU COMMAND
812 root 0.0 sshd
# press P: sort by CPU
# press M: sort by memory
Live View: top
$top# stays open; q to quittop - 19:08:23 up 1 day, 1 user
Tasks: 31 total, 1 running
%Cpu(s): 0.7 us, 98.6 id
MiB Mem : 7768.6 total
PID USER %CPU COMMAND
812 root 0.0 sshd# press P: sort by CPU# press M: sort by memory
More Examples: top
Watch one user only
Sort by memory at start
One snapshot, no live screen
$ top -u student
# only this user, less noise
$ top -o %MEM
# starts already sorted by memory
$ top -bn1 | head -15
# -b: batch mode, no live screen
# -n1: one iteration, then exit
# safe to pipe or save to a file
More Examples: top
$top-u student
# only this user, less noise$top-o %MEM
# starts already sorted by memory$top-bn1 | head-15# -b: batch mode, no live screen# -n1: one iteration, then exit# safe to pipe or save to a file
Use Case: top
See load as it happens
Spot the CPU or memory hog
Sort live, no scripts needed
Use Case: Live Triage
CPU is at 100% right now
top, then press P
The worst one is now on top
Reading the top Header
Header: machine health
Rows: one per process
Load above CPU count = busy
Find by Name: pgrep
Prints matching PIDs only
-a adds the full command
-c counts the matches
$ pgrep -a bash
# -a: PID plus the full command
812 -bash
$ pgrep -c bash
# -c: how many matches, not which
1
# ps | grep would also match itself
# pgrep never has that problem
Find by Name: pgrep
$pgrep-a bash
# -a: PID plus the full command812-bash$pgrep-c bash
# -c: how many matches, not which1# ps | grep would also match itself# pgrep never has that problem
More Examples: pgrep
Scope to one user
Match the full command line
Require an exact name
$ pgrep -u student sleep
# only this user's matching jobs
$ pgrep -f "http.server 8000"
# -f: matches ANYWHERE in the
# full command line, not just the name
$ pgrep -x bash
# -x: exact name only, not "bash-ish"
More Examples: pgrep
$pgrep-u student sleep# only this user's matching jobs$pgrep-f "http.server 8000"
# -f: matches ANYWHERE in the# full command line, not just the name$pgrep-x bash
# -x: exact name only, not "bash-ish"
Use Case: pgrep
Get a PID without reading ps
Avoid running a job twice
Feeds kill and monitoring
Use Case: Script Guard Clause
A cron job might overlap
pgrep checks before starting
Skip this run if one is active
Check: Find the Busy One
One process uses 99% CPU
You need its PID fast
Which tool, which key?
Answer: top shows live CPU use; press P to sort, read the PID column
$ sleep 300 &
# & starts it, already in the
[1] 2411
# background; 2411 is its PID
$ jobs
# lists every job THIS shell owns
[1]+ Running sleep 300 &
# Ctrl+Z pauses, bg resumes it
Background Jobs
$sleep300 &
# & starts it, already in the
[1] 2411# background; 2411 is its PID$jobs# lists every job THIS shell owns
[1]+ Running sleep300 &
# Ctrl+Z pauses, bg resumes it
More Examples: jobs
See the PID next to it
Resume a paused job quietly
Detach it from this shell
$ jobs -l
# -l adds the PID next to %1
$ bg %1
# resume a Ctrl+Z-paused job
# in the background, not foreground
$ disown %1
# detach it: survives you logging out
# (it keeps no connection to this shell)
More Examples: jobs
$jobs-l# -l adds the PID next to %1$bg %1
# resume a Ctrl+Z-paused job# in the background, not foreground$disown %1
# detach it: survives you logging out# (it keeps no connection to this shell)
Use Case: Background Jobs
Run a long job, keep working
Pause and resume with Ctrl+Z
Ends at logout unless nohup
Use Case: Free the Terminal
A long build blocks typing
Ctrl+Z, then bg
Terminal is free, job runs on
Stop a Process: kill
kill sends TERM by default
TERM: a request, can be caught
-9 KILL: kernel enforces it
$ kill 2411
# TERM: asks it to exit cleanly
$ kill -9 2411
# KILL: kernel ends it, no cleanup
$ pkill sleep
# pkill: same idea, matched by name
# not by PID -- careful with wide names
Stop a Process: kill
$kill2411# TERM: asks it to exit cleanly$kill-92411# KILL: kernel ends it, no cleanup$pkillsleep# pkill: same idea, matched by name# not by PID -- careful with wide names
More Examples: kill
List every signal by name
Ask a daemon to reload
Signal a whole process group
$ kill -l
# lists every signal name and number
$ kill -HUP 812
# HUP: many daemons reload config
# on HUP, instead of exiting
$ kill -- -2411
# a NEGATIVE pid signals the whole
# process group, not just one PID
More Examples: kill
$kill-l# lists every signal name and number$kill-HUP812# HUP: many daemons reload config# on HUP, instead of exiting$kill -- -2411# a NEGATIVE pid signals the whole# process group, not just one PID
Use Case: kill
Free memory from a stuck job
TERM lets it clean up first
KILL is the last resort
Use Case: Graceful Shutdown
Server holds open connections
TERM first, then wait
Only -9 if it will not stop
TERM Before KILL
Try TERM first, then wait
KILL skips all cleanup
Locks and temp files stay
Priority: nice, renice
Niceness runs -20 to 19
Lower number wins more CPU
Only root can go below 0
$ nice -n 10 sleep 300 &
# starts already at niceness 10
$ ps -o pid,ni,cmd -C sleep
# -o ni: show just the NI column
PID NI CMD
2411 10 sleep 300
$ renice -n 15 -p 2411
# renice: changes a job already
# running, by its PID
Priority: nice, renice
$nice-n10sleep300 &
# starts already at niceness 10$ps-o pid,ni,cmd -Csleep# -o ni: show just the NI column
PID NI CMD
241110sleep300$renice-n15-p2411# renice: changes a job already# running, by its PID
More Examples: nice
No -n: defaults to 10
Only root goes negative
A cousin command, for disk
$ nice sleep 300 &
# no -n given: niceness 10, not 0
$ sudo renice -n -5 -p 2411
# negative: needs root; more CPU
# than a normal process gets
$ ionice -c3 rsync src/ dst/
# ionice: same idea, for DISK I/O
# nice never touches disk priority
More Examples: nice
$nicesleep300 &
# no -n given: niceness 10, not 0$sudorenice-n-5-p2411# negative: needs root; more CPU# than a normal process gets$ionice-c3rsync src/ dst/
# ionice: same idea, for DISK I/O# nice never touches disk priority
Use Case: nice
Background work stays polite
Interactive users stay fast
Change priority while running
Use Case: Shared Server
A backup competes with logins
nice -n 15 on the backup
Logins stay fast; backup waits
Why It Is Called nice
nice
kind to the others
niceness
how much you defer
A high nice value lets everyone else go first. -20 is the most favored, 19 the least.
$ ssh-keygen -t ed25519 -C lab5
# -t: which key algorithm to use
Enter passphrase (empty for none):
# empty: convenient, but less safe
Your identification has been saved in
/home/student/.ssh/id_ed25519
# id_ed25519: PRIVATE, .pub: PUBLIC
Make a Key Pair
$ssh-keygen-t ed25519 -C lab5
# -t: which key algorithm to use
Enter passphrase (empty for none):
# empty: convenient, but less safe
Your identification has been saved in
/home/student/.ssh/id_ed25519
# id_ed25519: PRIVATE, .pub: PUBLIC
More Examples: ssh-keygen
A custom filename
Recover a lost public key
Check a key's fingerprint
$ ssh-keygen -t ed25519 -f ~/.ssh/id_lab
# -f: a custom filename, not the
# default -- lets you keep 2+ keys
$ ssh-keygen -y -f ~/.ssh/id_ed25519
# -y: print the PUBLIC half from
# the private file, if .pub is lost
$ ssh-keygen -l -f ~/.ssh/id_ed25519.pub
# -l: show the key's fingerprint
More Examples: ssh-keygen
$ssh-keygen-t ed25519 -f ~/.ssh/id_lab
# -f: a custom filename, not the# default -- lets you keep 2+ keys$ssh-keygen-y-f ~/.ssh/id_ed25519
# -y: print the PUBLIC half from# the private file, if .pub is lost$ssh-keygen-l-f ~/.ssh/id_ed25519.pub
# -l: show the key's fingerprint
Use Case: One Key, Many Servers
12 servers, one admin
ssh-keygen once
Copy it to each, no passwords
Use Case: Separate Keys Per Purpose
Work and personal, same laptop
ssh-keygen -f a 2nd file
Revoke just one, not both
Install Your Public Key
Appends to authorized_keys
Creates ~/.ssh if missing
Asks for the password once
$ ssh-copy-id localhost
# asks your PASSWORD once, to
# prove it's really you
Number of key(s) added: 1
# your public key is now trusted
Now try logging into the machine:
ssh 'localhost'
# output abbreviated
Install Your Public Key
$ssh-copy-id localhost
# asks your PASSWORD once, to# prove it's really you
Number of key(s) added: 1# your public key is now trusted
Now try logging into the machine:
ssh 'localhost'
# output abbreviated
More Examples: ssh-copy-id
Copy a specific key
A non-default port
The manual equivalent
$ ssh-copy-id -i ~/.ssh/id_lab.pub host
# -i: copy THIS key, not the default
$ ssh-copy-id -p 2222 user@host
# -p: server listens on a non-default port
$ cat ~/.ssh/id_ed25519.pub | \
ssh user@host 'cat >> ~/.ssh/authorized_keys'
# the manual version, automated by ssh-copy-id
More Examples: ssh-copy-id
$ssh-copy-id-i ~/.ssh/id_lab.pub host
# -i: copy THIS key, not the default$ssh-copy-id-p2222 user@host
# -p: server listens on a non-default port$cat ~/.ssh/id_ed25519.pub | \
ssh user@host 'cat >> ~/.ssh/authorized_keys'
# the manual version, automated by ssh-copy-id
Use Case: Lost Laptop
Revoke one key, not everyone
Remove its line on the server
No shared password to change
Use Case: Onboarding a New Admin
A new admin joins the team
ssh-copy-id to every server
No shared password, ever
Remember It: ssh-agent
The agent holds unlocked keys
ssh-add loads one key
Type the passphrase once
$ eval "$(ssh-agent -s)"
# starts the agent for this shell
Agent pid 3120
$ ssh-add ~/.ssh/id_ed25519
# unlocks once, holds it in memory
Identity added: id_ed25519 (lab5)
$ ssh-add -l
# -l: list what the agent has loaded
256 SHA256:HVKYQ0E... lab5 (ED25519)
Remember It: ssh-agent
$eval "$(ssh-agent -s)"
# starts the agent for this shell
Agent pid 3120$ssh-add ~/.ssh/id_ed25519
# unlocks once, holds it in memory
Identity added: id_ed25519 (lab5)
$ssh-add-l# -l: list what the agent has loaded256SHA256:HVKYQ0E... lab5 (ED25519)
More Examples: ssh-add
Auto-expire after an hour
Forget every loaded key
Print the full public keys
$ ssh-add -t 3600 ~/.ssh/id_ed25519
# -t: auto-expires in 1 hour, safer
# on a machine you don't fully trust
$ ssh-add -D
# -D: forget every key in the agent
$ ssh-add -L
# -L: print the FULL public keys
# (lowercase -l shows fingerprints)
More Examples: ssh-add
$ssh-add-t3600 ~/.ssh/id_ed25519
# -t: auto-expires in 1 hour, safer# on a machine you don't fully trust$ssh-add-D# -D: forget every key in the agent$ssh-add-L# -L: print the FULL public keys# (lowercase -l shows fingerprints)
$ cat ~/.ssh/id_ed25519.pub
ssh-ed25519 AAAAC3NzaC1... lab5
# paste this into GitHub, SSH keys
$ ssh -T git@github.com
Hi USERNAME! You've successfully
authenticated, but GitHub does not
provide shell access.
Log In With an SSH Key
$cat~/.ssh/id_ed25519.pub
ssh-ed25519 AAAAC3NzaC1... lab5
# paste this into GitHub, SSH keys$ssh-T git@github.com
Hi USERNAME! You've successfully
authenticated, but GitHub does not
provide shell access.
$ sudo sshd -t
# silent output = the config is valid
$ sudo systemctl reload ssh
# apply it without dropping sessions
$ sudo sshd -T | grep -i passwordauth
# -T prints every EFFECTIVE setting
passwordauthentication no
$ echo $?
# 0: the last command succeeded
Check Before You Reload
$sudosshd-t# silent output = the config is valid$sudo systemctl reload ssh# apply it without dropping sessions$sudosshd-T | grep-i passwordauth
# -T prints every EFFECTIVE setting
passwordauthentication no
$ echo $?
# 0: the last command succeeded
More Examples: sshd -t
Chain the check and reload
Preview a DRAFT file first
Check one setting is live
$ sudo sshd -t && sudo systemctl reload ssh
# reload runs ONLY if -t passed
$ sudo sshd -T -f ~/draft-sshd.conf
# -T -f: preview a DRAFT file's
# effect before it is ever installed
$ sudo sshd -T | grep -i permitroot
# check one specific setting is live
More Examples: sshd -t
$sudosshd-t && sudo systemctl reload ssh# reload runs ONLY if -t passed$sudosshd-T-f ~/draft-sshd.conf
# -T -f: preview a DRAFT file's# effect before it is ever installed$sudosshd-T | grep-i permitroot
# check one specific setting is live
$ sudo apt install -y curl
# curl: to prove the tunnel works
$ python3 -m http.server 8000 \
--bind 127.0.0.1 &
# a private service, localhost only
$ ssh -N -L 9000:localhost:8000 \
localhost &
# -N: no shell -L: forward this port
$ curl -s localhost:9000 | head -3
# arrives through the tunnel, not direct
Forward a Port: ssh -L
$sudoaptinstall-ycurl# curl: to prove the tunnel works$python3-m http.server 8000 \
--bind 127.0.0.1 &
# a private service, localhost only$ssh-N-L9000:localhost:8000 \
localhost &
# -N: no shell -L: forward this port$curl-s localhost:9000 | head -3
# arrives through the tunnel, not direct
More Examples: ssh -L
Reach a private service
2nd host: resolved by server
-f -N: keeps tunnel running
$ ssh -L 9000:localhost:8000 user@host
# reach the SERVER's own port 8000
# from YOUR OWN localhost:9000
$ ssh -L 5432:db.internal:5432 bastion
# db.internal: resolved by the SERVER
# not looked up on your own machine
$ ssh -f -N -L 9000:localhost:8000 host
# -f: keep running after login
# -N: no shell, tunnel only
More Examples: ssh -L
$ssh-L9000:localhost:8000 user@host
# reach the SERVER's own port 8000# from YOUR OWN localhost:9000$ssh-L5432:db.internal:5432 bastion
# db.internal: resolved by the SERVER# not looked up on your own machine$ssh-f-N-L9000:localhost:8000 host
# -f: keep running after login# -N: no shell, tunnel only
Use Case: Private Page
Admin pages stay off the web
Reach them through ssh only
No new firewall holes
Use Case: Reaching a Database
App needs an internal DB
Reach it through one bastion
No new firewall holes
Sync Folders: rsync
Copies only what changed
-a keeps modes and times
-n is a safe dry run
$ sudo apt install -y rsync
# not installed by default
$ mkdir -p ~/lab5
$ rsync -avn ~/lab5/ localhost:lab5-copy/
# -n: DRY RUN, shows the plan only
sending incremental file list
$ rsync -av ~/lab5/ localhost:lab5-copy/
# trailing / copies the folder's contents
Sync Folders: rsync
$sudoaptinstall-yrsync# not installed by default$ mkdir -p ~/lab5
$rsync-avn ~/lab5/ localhost:lab5-copy/# -n: DRY RUN, shows the plan only
sending incremental file list
$rsync-av ~/lab5/ localhost:lab5-copy/# trailing / copies the folder's contents
More Examples: rsync
Also delete removed files
Compress for a slow link
Skip matching files
$ rsync -av --delete ~/lab5/ dst/
# --delete: ALSO remove files at dst
# that no longer exist at the source
$ rsync -avz ~/lab5/ localhost:dst/
# -z: compress in transit
$ rsync -av --exclude '*.log' ~/lab5/ dst/
# skip files matching this pattern
More Examples: rsync
$rsync-av--delete ~/lab5/ dst/
# --delete: ALSO remove files at dst# that no longer exist at the source$rsync-avz ~/lab5/ localhost:dst/
# -z: compress in transit$rsync-av--exclude '*.log' ~/lab5/ dst/
# skip files matching this pattern
Use Case: Nightly Backup
Copy only what changed
A dry run shows it first
A re-run picks up the rest
Use Case: Safe Delete Sync
A local folder was cleaned up
rsync -av --delete
Backup matches exactly now
Word Origin: "Multiplexer"
multi
Latin: many
plex
Latin: fold
A terminal multiplexer folds many terminals into one window. tmux is one.
$ sudo apt install -y tmux
# not installed by default
$ tmux new -s work
# starts a NEW named session
# run a long job, then Ctrl+b and d
# Ctrl+b d: DETACHES, job keeps going
$ tmux ls
work: 1 windows (created ...)
$ tmux attach -t work
# reattach: right where you left off
Keep a Session: tmux
$sudoaptinstall-ytmux# not installed by default$tmux new -s work
# starts a NEW named session# run a long job, then Ctrl+b and d# Ctrl+b d: DETACHES, job keeps going$tmux ls
work: 1 windows (created ...)
$tmux attach -t work
# reattach: right where you left off
More Examples: tmux
Create it already detached
End a session you are done
Split the window, one keybind
$ tmux new -s upgrade -d
# -d: create it ALREADY detached
$ tmux kill-session -t work
# ends a session you no longer need
# Ctrl+b % splits the pane vertically
# Ctrl+b " splits it horizontally
# both stay in the SAME session
More Examples: tmux
$tmux new -s upgrade -d# -d: create it ALREADY detached$tmux kill-session -t work
# ends a session you no longer need# Ctrl+b % splits the pane vertically# Ctrl+b " splits it horizontally# both stay in the SAME session
Use Case: Long Upgrade
Wi-Fi drops, the job survives
Reattach and check progress
Half-finished upgrades hurt
Use Case: Watch Two Things at Once
Watch a log, run a command
Ctrl+b % splits the pane
One window, two views
Why tmux Survives
Closing a terminal sends HUP
nohup ignores that signal
tmux runs its own server
Check: Copy a Big Folder
10,000 files, one changed
The link is slow
scp or rsync?
Answer: it sends only the changed file; scp would resend all 10,000
Questions?
Practice Lab
Lab at a Glance
Everything runs on one VM
Nine short steps
Proof: screenshots and output
Step 1: Watch and Filter
ps: one snapshot, right now
pgrep: filter by name only
jobs: your shell's own list
$ sleep 300 &
# start a background job to look for
$ ps aux | grep sleep
# ps: a one-time snapshot, PID here
$ pgrep -a sleep
# pgrep: just the match, no ps needed
$ top -bn1 | head -8
# top -bn1: one snapshot, no live screen
$ jobs
[1]+ Running sleep 300 &
Step 1: Watch and Filter
$sleep300 &
# start a background job to look for$ps aux | grepsleep# ps: a one-time snapshot, PID here$pgrep-asleep# pgrep: just the match, no ps needed$top-bn1 | head-8# top -bn1: one snapshot, no live screen$jobs
[1]+ Running sleep300 &
Step 2: Install sshd
Not installed by default
Add curl, rsync, tmux too
Confirm port 22 listens
$ sudo apt install -y openssh-server \
curl rsync tmux python3
# sshd plus the tools used in this lab
$ sudo systemctl enable --now ssh
# start sshd now and at every boot
$ ss -tln | grep :22
# confirm something listens on port 22
Step 2: Install sshd
$sudoapt install -y openssh-server \
curl rsync tmux python3
# sshd plus the tools used in this lab$sudosystemctl enable --now ssh
# start sshd now and at every boot$ss-tln | grep :22
# confirm something listens on port 22
Step 3: Key Login
Keygen on KALI, not Ubuntu
Copies to Ubuntu's account
Then log in with no password
# On Ubuntu: find its IP and user
$ hostname -I
$ whoami
# On Kali: make a key, no passphrase
$ ssh-keygen -t ed25519 -N "" -C lab5
$ ssh-copy-id UBUNTU_USER@UBUNTU_IP
# yes to the fingerprint, then password
$ ssh UBUNTU_USER@UBUNTU_IP hostname
# prints Ubuntu's hostname, no password
Step 3: Key Login
# On Ubuntu: find its IP and user$hostname-I$whoami# On Kali: make a key, no passphrase$ssh-keygen-t ed25519 -N""-C lab5
$ssh-copy-idUBUNTU_USER@UBUNTU_IP# yes to the fingerprint, then password$sshUBUNTU_USER@UBUNTU_IPhostname# prints Ubuntu's hostname, no password
Check: Which Port?
Back on Ubuntu's terminal
sshd is installed and up
Something must listen
On which port?
Answer: ss -tln | grep :22 shows the listener
Step 4: Write the Policy
Drop-in file named 10-lab
Passwords off, root off
Keep this terminal open
$ echo "PasswordAuthentication no" | \
sudo tee \
/etc/ssh/sshd_config.d/10-lab.conf
# passwords off: keys only from now on
$ echo "PermitRootLogin no" | \
sudo tee -a \
/etc/ssh/sshd_config.d/10-lab.conf
# -a adds a second line to the same file
Step 4: Write the Policy
$echo"PasswordAuthentication no" | \
sudotee \
/etc/ssh/sshd_config.d/10-lab.conf# passwords off: keys only from now on$echo"PermitRootLogin no" | \
sudotee-a \
/etc/ssh/sshd_config.d/10-lab.conf# -a adds a second line to the same file
Step 5: Test and Reload
-t checks, silently
reload keeps live sessions
Password login must fail
$ sudo sshd -t
# silent means the config is valid
$ sudo systemctl reload ssh
# apply it without dropping sessions
$ sudo sshd -T | grep -i passwordauth
# shows the effective setting
$ ssh -o PubkeyAuthentication=no localhost
# expect: Permission denied (publickey)
Step 5: Test and Reload
$sudosshd-t# silent means the config is valid$sudosystemctl reload ssh
# apply it without dropping sessions$sudosshd-T | grep-i passwordauth
# shows the effective setting$ssh-o PubkeyAuthentication=no localhost
# expect: Permission denied (publickey)
Check: Password Refused?
Password login is now off
ssh -o PubkeyAuthentication=no
What error do you expect?
Answer: only key logins are offered, so the password path is gone
Step 6: Run a Job
nice starts it politely
ps -o shows the NI column
pkill stops it by name
$ nice -n 10 sleep 600 &
# start a low-priority background job
$ ps -o pid,ni,cmd -C sleep
# the NI column shows the niceness, 10
$ pkill sleep
# stop it by name
Step 6: Run a Job
$nice-n10 sleep 600 &
# start a low-priority background job$ps-o pid,ni,cmd -C sleep
# the NI column shows the niceness, 10$pkill sleep
# stop it by name
Step 7: Tunnel a Page
A tiny web server on 8000
A tunnel from 9000 to it
curl proves it works
$ python3 -m http.server 8000 \
--bind 127.0.0.1 &
# a tiny web server on port 8000
$ ssh -N -L 9000:localhost:8000 \
localhost &
# forward local port 9000 through ssh
$ curl -s localhost:9000 | head -3
# the page arrives through the tunnel
Step 7: Tunnel a Page
$python3-m http.server 8000 \
--bind 127.0.0.1 &
# a tiny web server on port 8000$ssh-N-L 9000:localhost:8000 \
localhost &
# forward local port 9000 through ssh$curl-s localhost:9000 | head -3
# the page arrives through the tunnel
Step 8: A Second Tunnel
Two ports, one ssh command
-L can repeat per tunnel
ss confirms both listening
$ python3 -m http.server 5000 \
--bind 127.0.0.1 &
# a second private service, port 5000
$ ssh -N \
-L 9000:localhost:8000 \
-L 9500:localhost:5000 \
localhost &
# -L can repeat: one tunnel, 2 ports
$ ss -tln | grep -E '9000|9500'
# both local ports are now listening
Step 8: A Second Tunnel
$python3-m http.server 5000 \
--bind 127.0.0.1 &
# a second private service, port 5000$ssh-N \
-L9000:localhost:8000 \
-L9500:localhost:5000 \
localhost &
# -L can repeat: one tunnel, 2 ports$ss-tln | grep -E '9000|9500'
# both local ports are now listening
Step 9: Sync and Persist
rsync copies over ssh
tmux -d starts it detached
pkill -f stops the helpers
$ mkdir -p ~/lab5 && touch ~/lab5/a.txt
# a folder with one empty file
$ rsync -av ~/lab5/ localhost:lab5-copy/
# copy it over ssh
$ tmux new -s work -d
# a session that survives logout
$ pkill -f "http.server|ssh -N"
# stop the web server and the tunnel
Step 9: Sync and Persist
$mkdir-p~/lab5 && touch~/lab5/a.txt# a folder with one empty file$rsync-av~/lab5/localhost:lab5-copy/# copy it over ssh$tmux new -s work -d# a session that survives logout$pkill-f"http.server|ssh -N"# stop the web server and the tunnel
Deliverables
Screenshot: key login works
Screenshot: password refused
Paste: sshd -T passwordauth
Paste: ps line with NI 10
Paste: curl via the tunnel
Paste: ss shows both ports
Paste: jobs shows it running
Questions?
Practice Lab Part 2
Practice Lab Part 2, Q1
How do you find the process using the most CPU?
$ps aux --sort=-%cpu | head-5# --sort=-%cpu: busiest# process first
Practice Lab Part 2, Q2
How do you save one live snapshot of top's output to a file?
$top-bn1 > snapshot.txt
# -b: batch, -n1: one pass,# then exit
Practice Lab Part 2, Q3
How do you check if nginx is already running?
$pgrep-a nginx
# -a: shows the PID and# full command
Practice Lab Part 2, Q4
How do you free your terminal without stopping the job in it?
$ Ctrl+Z
$ bg
# Ctrl+Z pauses; bg resumes# it in the background
Practice Lab Part 2, Q5
How do you stop a process that won't respond to a normal request?
$kill-9 PID
# -9 (KILL): kernel forces# it, no cleanup
Practice Lab Part 2, Q6
How do you run a heavy job without slowing down other users?
$nice-n15 command
# 15: low priority, yields# CPU on demand
Practice Lab Part 2, Q7
How do you make a new SSH key with no passphrase, for a lab only?
$ssh-keygen-ted25519-N ""
# -N "": empty passphrase,# less safe but convenient
Practice Lab Part 2, Q8
How do you avoid retyping your key's passphrase all day?
$eval "$(ssh-agent -s)"
$ssh-add~/.ssh/id_ed25519# unlocks it once, holds it# in memory
Practice Lab Part 2, Q9
How do you reach a database that only listens on the server's own localhost?
$ssh-L5432:localhost:5432 \
user@host
# -L: tunnels the remote# port to your own machine
Practice Lab Part 2, Q10
How do you copy a folder without resending files already up to date?
$rsync-av src/ user@host:dst/
# -a: archive mode, -v:# verbose; only diffs sent
Questions?
Practice Lab Part 3
Scenario: Your Medical Unit
Ubuntu VM = a medical unit server
Kali VM = your operator machine
You connect Kali → Ubuntu over SSH
Task: find which processes belong
Step 1: Confirm You're on Kali
Check your own machine first
whoami shows the logged-in user
hostname shows the machine name
$ whoami
# confirms which account you are using
kali
$ hostname
# confirms which machine you are on
kali
Step 1: Confirm You're on Kali
$whoami# confirms which account you are using
kali
$hostname# confirms which machine you are on
kali
Step 2: Find the Unit's Real IP
Run this on the Ubuntu VM
hostname -I: this machine's IP
Write it down for the next step
$ hostname -I
# -I: this machine's own IP address
10.0.2.15
Step 2: Find the Unit's Real IP
$hostname-I# -I: this machine's own IP address10.0.2.15
Step 3: Ping the Unit
Still on Kali, using the raw IP
Confirms basic reachability
Do this before trying SSH at all
$ ping -c 3 10.0.2.15
# -c 3: send exactly 3 pings, then stop
64 bytes from 10.0.2.15: icmp_seq=1
64 bytes from 10.0.2.15: icmp_seq=2
64 bytes from 10.0.2.15: icmp_seq=3
0% packet loss
Step 3: Ping the Unit
$ ping -c310.0.2.15# -c 3: send exactly 3 pings, then stop64 bytes from 10.0.2.15: icmp_seq=1
64 bytes from 10.0.2.15: icmp_seq=2
64 bytes from 10.0.2.15: icmp_seq=3
0% packet loss
Step 4: Verify Your Sudo Account
On the medical unit's own console
sudo -l: what you are allowed to run
Confirm this before Step 6 needs it
$ sudo -l
# -l: list what you are allowed to run
User ubuntu may run:
(ALL : ALL) ALL
Step 4: Verify Your Sudo Account
$sudo-l# -l: list what you are allowed to run
User ubuntu may run:
(ALL : ALL) ALL
Step 5: Name the Medical Unit
Back on Kali now
Map a friendly name to that IP
Avoids clashing with a real DNS name
$ echo "10.0.2.15 medical-unit" \
| sudo tee -a /etc/hosts
# tee -a: appends to /etc/hosts as root
$ getent hosts medical-unit
# confirms the mapping now resolves
10.0.2.15 medical-unit
Step 5: Name the Medical Unit
$echo "10.0.2.15 medical-unit" \
| sudo tee -a /etc/hosts
# tee -a: appends to /etc/hosts as root$ getent hosts medical-unit
# confirms the mapping now resolves10.0.2.15 medical-unit
Step 6: Make Your SSH Key
Generate a keypair on Kali
ed25519: modern, short, fast
Private key never leaves Kali
$ ssh-keygen -t ed25519
# -t ed25519: modern, compact key type
Enter file: (press Enter)
Enter passphrase: (press Enter)
$ ls ~/.ssh/id_ed25519.pub
# confirms the public key was created
/home/kali/.ssh/id_ed25519.pub
Step 6: Make Your SSH Key
$ssh-keygen-t ed25519
# -t ed25519: modern, compact key type
Enter file: (press Enter)
Enter passphrase: (press Enter)
$ ls ~/.ssh/id_ed25519.pub# confirms the public key was created/home/kali/.ssh/id_ed25519.pub
Step 7: Set a Password Once
On the medical unit, one time only
ssh-copy-id needs a first login
passwd sets it for your account
$ sudo passwd $(whoami)
# sets a login password for this account
New password: ********
$ passwd -S $(whoami)
# -S: shows the account's password status
ubuntu P 09/24/2026 0 99999 7 -1
Step 7: Set a Password Once
$sudopasswd $(whoami)
# sets a login password for this account
New password: ********
$passwd-S $(whoami)
# -S: shows the account's password status
ubuntu P 09/24/2026 0999997 -1
Step 8: Copy Your Public Key
Back on Kali
ssh-copy-id sends the public half
Only *.pub ever leaves your machine
$ ssh-copy-id $(whoami)@medical-unit
# sends only your *.pub file to the unit
Password: ********
Number of key(s) added: 1
$ ssh-copy-id $(whoami)@medical-unit
# re-run: 0 added means it is already there
Number of key(s) added: 0
Step 8: Copy Your Public Key
$ssh-copy-id $(whoami)@medical-unit
# sends only your *.pub file to the unit
Password: ********
Number of key(s) added: 1$ssh-copy-id $(whoami)@medical-unit
# re-run: 0 added means it is already there
Number of key(s) added: 0
Step 9: Connect With Your Key
Same command as always: ssh
No password prompt this time
You are logged in to the unit
$ ssh $(whoami)@medical-unit
# no -i needed: ssh-agent offers it for you
Welcome to Ubuntu 24.04 LTS
Step 9: Connect With Your Key
$ssh $(whoami)@medical-unit
# no -i needed: ssh-agent offers it for you
Welcome to Ubuntu 24.04 LTS
Check: Why No Password?
SSH just let you in with no password prompt. What actually proved who you are?
Your private key, still only on Kali, mathematically proved you hold the matching public key already sitting in the unit's authorized_keys file. Nothing secret ever crossed the network.
Step 10: Get the Lab From GitHub
Still connected to the unit
Clone the class repository
Every module's labs live here
$ git clone https://github.com/
SE4CPS/2026-COMP-175
# clones the whole class repo, once
$ ls 2026-COMP-175
# confirms the clone actually landed
modules README.md
Step 10: Get the Lab From GitHub
$gitclone https://github.com/
SE4CPS/2026-COMP-175
# clones the whole class repo, once$ ls 2026-COMP-175
# confirms the clone actually landed
modules README.md
Step 11: Go to This Lab's Folder
cd into module 5's practice lab
ls shows the scripts inside
spawn.sh starts everything
$ cd 2026-COMP-175/modules/
module-5/practicelab3
# this lab's own folder
$ ls
# spawn.sh is what starts everything
spawn.sh vitals-logger.sh ...
Step 11: Go to This Lab's Folder
$cd 2026-COMP-175/modules/
module-5/practicelab3
# this lab's own folder$ ls
# spawn.sh is what starts everything
spawn.sh vitals-logger.sh ...
Step 12: Start the Unit's Processes
Runs 4 background jobs at once
nohup + disown: survive logout
Returns right away, not stuck
$ bash spawn.sh
# launches all 4 jobs, nohup'd + disowned
Started 4 background processes.
$ pgrep -c -f "logger|sync|job|nightly"
# -c: just count the matches
4
Step 12: Start the Unit's Processes
$bash spawn.sh
# launches all 4 jobs, nohup'd + disowned
Started 4 background processes.
$pgrep-c-f "logger|sync|job|nightly"
# -c: just count the matches4
Check: Why Does "Right Away" Matter?
spawn.sh printed its message and gave your prompt back immediately instead of hanging. Why is that the point of nohup and disown here?
A medical unit's monitoring jobs have to keep running after you log out; if the command hung waiting on your terminal, closing the SSH session would kill everything with it instead of leaving it running unattended.
Step 13: List Every Process
ps aux: every process, every user
A busy list, hard to scan
Next step narrows it down
$ ps aux
# aux: every process, every user, full cmd
USER PID %CPU COMMAND
...
Step 13: List Every Process
$ps aux
# aux: every process, every user, full cmd
USER PID %CPU COMMAND
...
Step 14: Narrow to This Lab's Jobs
pgrep -a: match by name pattern
Only the 4 processes we started
Note each PID for later
$ pgrep -a -f "logger|sync|job|nightly"
# -a: also show each match's full command
2201 vitals-logger.sh
2202 labsync.sh
2203 stuck-job.sh
2204 backup-nightly.sh
Step 14: Narrow to This Lab's Jobs
$pgrep-a-f "logger|sync|job|nightly"
# -a: also show each match's full command2201 vitals-logger.sh
2202 labsync.sh
2203 stuck-job.sh
2204 backup-nightly.sh
Check: Low CPU Means Safe?
Two of these four barely use any CPU right now. Does low CPU usage alone prove a process is needed?
No. CPU usage only measures how busy something is, not whether the unit still needs it; a forgotten job can sit idle and low-CPU for days while still being the wrong thing to leave running.
Step 15: Watch Live Usage
top: a live, sorted view
Sorted by CPU, highest first
One process should stand out
$ top
# live view, sorted by CPU by default
PID %CPU COMMAND
2203 98.7 stuck-job.sh
2204 4.1 backup-nightly.sh
2201 0.1 vitals-logger.sh
Step 15: Watch Live Usage
$top# live view, sorted by CPU by default
PID %CPU COMMAND
220398.7 stuck-job.sh
22044.1 backup-nightly.sh
22010.1 vitals-logger.sh
Check: Is High CPU Alone the Proof?
stuck-job.sh is pinned near 100% CPU with no sign of slowing down. Is high CPU by itself always a reason to kill something?
Not always: a real batch job can legitimately max a core for a while; what actually condemns stuck-job.sh here is that it never lets up and does not match anything the unit is supposed to be running.
Step 16: Check the Schedule, Not Just Load
backup-nightly is meant for overnight
It is running right now, mid-shift
Timing is the real problem here
$ date
# confirms the unit's own current time
Mon Sep 23 02:14:00 PM PDT 2026
Step 16: Check the Schedule, Not Just Load
$ date
# confirms the unit's own current time
Mon Sep 23 02:14:00 PM PDT 2026
Check: Why Flag backup-nightly Too?
backup-nightly.sh only used about 4% CPU in Step 15, far below stuck-job.sh. Why does it still belong on your list?
A process can be "needed" in general but wrong right now: backup-nightly.sh is only supposed to run overnight, so seeing it mid-afternoon is the actual problem, not how much CPU it happens to be using.
Step 17: End the Runaway Job
kill takes a PID, not a name
Use the PID pgrep found earlier
Default signal: SIGTERM, ask nicely
$ kill 2203
# default signal: SIGTERM, ask nicely first
$ pgrep -f stuck-job; echo $?
# exit 1 = no match = the process is gone
1
Step 17: End the Runaway Job
$kill2203# default signal: SIGTERM, ask nicely first$pgrep-f stuck-job; echo $?
# exit 1 = no match = the process is gone1
Check: Why kill and Not pkill Here?
You could have run pkill stuck-job instead of kill 2203. Why use the exact PID in a real triage like this?
kill with a specific PID only ever ends the one process you already confirmed; pkill matches by name across the whole system, which risks catching something else with a similar name you never meant to touch.
Step 18: End the Mistimed Job
Same idea, different PID
backup-nightly can run tonight
Not now, during the shift
$ kill 2204
# same signal, different PID this time
$ pgrep -f backup-nightly; echo $?
# exit 1 confirms it is no longer running
1
Step 18: End the Mistimed Job
$kill2204# same signal, different PID this time$pgrep-f backup-nightly; echo $?
# exit 1 confirms it is no longer running1
Step 19: Confirm the Cleanup
Re-run the same pgrep as Step 14
Only 2 processes should remain
Both are ones the unit needs
$ pgrep -a -f "logger|sync|job|nightly"
# same command as Step 14, run again
2201 vitals-logger.sh
2202 labsync.sh
Step 19: Confirm the Cleanup
$pgrep-a-f "logger|sync|job|nightly"
# same command as Step 14, run again2201 vitals-logger.sh
2202 labsync.sh
cron runs in the background all day. Is it a service, a process, or both?
Answer
Both. It is a process (it has a PID) that systemd manages as the service cron.service.
Questions?
Checking Services
One Service: status
status shows one service
State, PID and recent logs
No sudo needed to read it
$ systemctl status cron
# state of one service
● cron.service - Regular ...
Loaded: loaded (...; enabled)
Active: active (running)
Main PID: 512 (cron)
# q quits; output trimmed
$ systemctl is-active cron
# one word: active or inactive
active
One Service: status
$systemctl status cron
# state of one service
● cron.service - Regular ...
Loaded: loaded (...; enabled)
Active: active (running)
Main PID: 512 (cron)
# q quits; output trimmed$systemctl is-active cron
# one word: active or inactive
active
Reading status
Loaded: is the file found?
Active: running, failed...
Bottom lines: recent logs
List All: list-units
Every loaded unit, one a line
--type=service: services only
--state narrows it further
$ systemctl list-units \
--type=service --state=running
# only services running now
UNIT ACTIVE SUB
cron.service active running
ssh.service active running
# 3 columns kept to fit
List All: list-units
$systemctl list-units \
--type=service--state=running# only services running now
UNIT ACTIVE SUB
cron.service active running
ssh.service active running
# 3 columns kept to fit
Use Case: Failed Portal
The portal reports errors
status shows Active: failed
The log lines say why
Check: Read the Status
status shows Active: failed. Where do you look first to learn why?
Answer
The log lines at the bottom of systemctl status, or run journalctl -u NAME for the full log.
Check: Script Test
Which command prints only active or inactive, so a script can test it?
Answer
systemctl is-active NAME. It prints one word and sets the exit code.
Questions?
Starting & Stopping
Start and Stop
start runs it now
stop ends it now
Both need sudo
$ sudo systemctl start cron
# no output means it worked
$ sudo systemctl stop cron
# stop it now
$ systemctl is-active cron
# check the result
inactive
Start and Stop
$sudosystemctl start cron
# no output means it worked$sudosystemctl stop cron
# stop it now$systemctl is-active cron
# check the result
inactive
Restart and Reload
restart: stop, then start
reload: reread the config
Reload needs service support
$ sudo systemctl restart cron
# stop, then start again
$ sudo systemctl reload ssh
# reread config, keep running
# not every service can reload
⚠️ Restart drops open connections; reload keeps them.
Restart and Reload
$sudosystemctl restart cron
# stop, then start again$sudosystemctl reload ssh
# reread config, keep running# not every service can reload
Use Case: Config Change
You edited the settings
Users must stay connected
Reload applies it in place
Check: Restart or Reload?
You edited a service's settings, and users must stay connected. Restart or reload?
Answer
Reload, if the service supports it. Restart stops the service first, so connections drop.
Check: Stopped Means Gone?
You ran systemctl stop cron. Will cron be running after the next reboot?
Answer
Yes, if it is enabled. stop only ends it now. Boot behavior is set by enable and disable.
Questions?
Boot & Enable
Word Origin: "Boot"
bootstrap
a loop of leather on a boot
boot
pull yourself up, 1970s
A computer boots by pulling itself up: a tiny program loads the rest.
$ sudo systemctl enable cron
# start automatically at boot
$ systemctl is-enabled cron
enabled
$ sudo systemctl disable cron
# not at boot; runs until stop
$ sudo systemctl enable --now \
cron
# enable and start together
Boot Behavior: enable
$sudosystemctl enable cron
# start automatically at boot$systemctl is-enabled cron
enabled
$sudosystemctl disable cron
# not at boot; runs until stop$sudosystemctl enable --now \
cron# enable and start together
Enable vs Start
start: now, this boot only
enable: every boot, not now
enable --now: both
Slow Boot: analyze
Total boot time, split up
blame: slowest units first
Numbers differ per machine
$ systemd-analyze
# total boot time
Startup finished in 12.9s
$ systemd-analyze blame | \
head -3
# slowest units first
3.2s apt-daily.service
# example numbers only
Slow Boot: analyze
$systemd-analyze# total boot time
Startup finished in 12.9s
$systemd-analyze blame | \
head-3# slowest units first
3.2s apt-daily.service
# example numbers only
Use Case: Survive a Reboot
The service died after reboot
It was started, never enabled
enable fixes the next boot
Check: Start or Enable?
You ran systemctl start NAME. Will it run after the next reboot?
Answer
Not unless it is enabled. start acts now; enable links it into the boot process.
Check: Slow Boot
Which command lists the units that took the longest to start?
Answer
systemd-analyze blame. It lists every unit with its start time, slowest first.
Questions?
Reading Logs
Word Origin: "Journal"
diurnalis
Late Latin: daily
jornel
Old French: a day's record
A journal is a daily record, and journald keeps one for every service.
$ journalctl -n 3
# last 3 lines, all services
Sep 26 18:09 vm-ubuntu ...
Sep 26 18:09 systemd[1]: ...
$ journalctl -b
# everything since this boot
Read the Log: journalctl
$journalctl-n3# last 3 lines, all services
Sep 26 18:09 vm-ubuntu ...
Sep 26 18:09 systemd[1]: ...
$journalctl-b# everything since this boot
More Examples: journalctl
-u: one service only
-p err: errors and worse
-f: follow live
$ journalctl -u cron
# just the cron service
$ journalctl -p err
# errors only
$ journalctl --since \
"10 min ago"
# a time window
$ journalctl -u cron -f
# live; Ctrl+C to stop
More Examples: journalctl
$journalctl-u cron
# just the cron service$journalctl-p err
# errors only$journalctl--since \
"10 min ago"# a time window$journalctl-u cron -f# live; Ctrl+C to stop
Use Case: Trace an Outage
Users lost service at 9:40
Filter the journal by time
The first error is the cause
Word Origin: "Log"
log-book
a ship's daily record
log
a record of events
Sailors logged speed with a weighted log on a line; the record kept the name.
$ sudo sed -i \
's/Restart=on-failure/Restart=always/' \
/etc/systemd/system/beat.service
# stream-edit one line, no editor
$ sudo systemctl daemon-reload
# needed after every change
⚠️ Skip daemon-reload and systemd may keep using the old file.
After Editing: reload
$sudosed-i \
's/Restart=on-failure/Restart=always/' \
/etc/systemd/system/beat.service# stream-edit one line, no editor$sudosystemctl daemon-reload
# needed after every change
Word Origin: "Mask"
masca
Medieval Latin: a mask
maschera
Italian: a face covering
A masked unit is covered over: nothing can start it, even by hand.
$ sudo systemctl mask cups
# now it cannot be started
$ sudo systemctl start cups
Failed to start cups.service:
Unit cups.service is masked.
$ sudo systemctl unmask cups
# allowed to start again
Block a Unit: mask
$sudosystemctl mask cups
# now it cannot be started$sudosystemctl start cups
Failed to start cups.service:
Unit cups.service is masked.
$sudosystemctl unmask cups
# allowed to start again
Use Case: Block a Service
A service must never run
disable still allows starts
mask blocks every start
Check: Edited a Unit File
You changed a unit file, but systemd still uses the old settings. Why?
Answer
systemd caches unit files. Run sudo systemctl daemon-reload, then restart the service.
Check: Masked or Disabled?
What is the difference between disable and mask?
Answer
disable only stops the start at boot. mask blocks every start, even a manual one.
Questions?
Timers & Cron
Word Origin: "Cron"
chronos
Greek: time
cron
the scheduler daemon
The Unix scheduler took its name from the Greek word for time.
You saved beat.service. Why run daemon-reload before you start it?
Answer
So systemd rereads the unit files. Skipping it can leave systemd on stale settings.
Step 3: Reload and Start
daemon-reload rereads files
start runs the new service
is-active confirms it
$ sudo systemctl daemon-reload
# systemd reads the new file
$ sudo systemctl start beat
# no output means it worked
$ systemctl is-active beat
active
Step 3: Reload and Start
$sudosystemctl daemon-reload
# systemd reads the new file$sudosystemctl start beat
# no output means it worked$systemctl is-active beat
active
Step 4: Read Its Log
-u beat: only this service
-n 3: the last 3 lines
status also shows Main PID
$ journalctl -u beat -n 3
# what systemd logged for beat
Started beat.service -
Registrar heartbeat.
$ systemctl status beat | head -4
# note the Main PID
Step 4: Read Its Log
$journalctl-u beat -n3# what systemd logged for beat
Started beat.service -
Registrar heartbeat.
$systemctl status beat | head -4# note the Main PID
Step 5: Kill It
Force-kill all its processes
on-failure brings it back
A NEW Main PID appears
$ sudo systemctl kill -s KILL beat
# force-kill it
$ systemctl status beat | head -4
# a new Main PID: it returned
$ systemctl show beat \
-p NRestarts
NRestarts=1
Step 5: Kill It
$sudosystemctl kill -s KILL beat
# force-kill it$systemctl status beat | head -4# a new Main PID: it returned$systemctl show beat \
-p NRestarts
NRestarts=1
Check: Read the Restart
Which journal line proves systemd restarted beat after the kill?
Answer
Scheduled restart job, restart counter is at 1. Run journalctl -u beat -n 6 to see it.
A machine can reach 192.168.1.1 but not google.com. Which of the three pieces is most likely missing?
Answer
The resolver. Reaching the gateway proves the address and route work; only DNS resolution is failing.
Questions?
L2/L3: Viewing Interfaces
Why Check Interfaces?
Confirm before you diagnose
A DOWN interface stops all
Cheapest, fastest first check
See Every Interface: ip addr
Lists every network interface
Shows each one's IP address
No sudo needed to just look
$ ip addr show
# every interface on this machine
1: lo: <LOOPBACK,UP>
inet 127.0.0.1/8 scope host lo
2: eth0: <BROADCAST,UP>
inet 192.168.1.50/24 ...
See Every Interface: ip addr
$ip addr show
# every interface on this machine
1: lo: <LOOPBACK,UP>
inet 127.0.0.1/8 scope host lo
2: eth0: <BROADCAST,UP>
inet 192.168.1.50/24 ...
# ip -br addr show: compact, one line per interface# ip addr show eth0: just that one interface# ip -4 addr show: IPv4 addresses only
Reading ip addr
lo: the loopback, always there
eth0: a real network interface
inet: the IPv4 address itself
Bring an Interface Up: ip link
link shows/sets up or down
sudo needed to change it
Down means no traffic
$ ip link show eth0
# state is UP or DOWN
$ sudo ip link set eth0 up
# turn the interface on
Bring an Interface Up: ip link
$ip link show eth0
# state is UP or DOWN$sudo ip link set eth0 up
# turn the interface on# ip link show: every interface, not just one# sudo ip link set eth0 down: turn it off instead# ip -s link show eth0: adds packet/error counts
eth0: Down vs. Up
Down: carries no traffic
No ping, SSH, or DHCP
Up: ready to send/receive
Still needs an IP to route
Check: Address vs Link?
eth0 shows state UP but ip addr shows no inet line for it. What does that tell you?
Answer
The interface itself is active, but it has no IP address assigned yet: a configuration step is still missing.
Questions?
L3: IP Addresses & Subnets
Why Subnets Matter
One scheme, every location
Overlap breaks routing
Confidentiality crosses shops
Finding Your Own IP
Quickest IP lookup there is
No need to parse ip addr
Handy inside quick scripts
$ hostname -I
10.0.0.192
Finding Your Own IP
$hostname-I# prints every IP this host has10.0.0.192# hostname: name only, no IP# hostname -i: lowercase, unreliable# hostname -I: uppercase, all addrs
CIDR Notation
/24 means 24 network bits
Fewer host bits, fewer hosts
/24 = 256 addrs, 254 usable
Private Address Ranges
Reserved, never public
Free to reuse on any LAN
A router/NAT bridges out
CIDR
Classless Inter-Domain
Routing
1993
RFC 1519, replacing fixed
Class A/B/C sizes
⚠️ Before CIDR, every network was a fixed Class A/B/C size: wasteful and inflexible.
⚠️ A subnet that doesn't match your real network can disconnect the VM entirely once applied: always use your own values from ip addr/ip route, never a copied example.
netplan try previews a config and auto-reverts if you never confirm it. Why is that useful over netplan apply?
Answer
A bad static config over SSH can lock you out immediately. try rolls back automatically if you lose the connection.
Questions?
L3: Routing & Gateway
Why Routing Matters
Local traffic still works fine
Everything outside fails
The gateway is the one exit
See the Routing Table: ip route
default via ...: the gateway
Local networks need no gateway
No sudo needed to just look
$ ip route show
# the routing table
default via 192.168.1.1 dev eth0
192.168.1.0/24 dev eth0 ...
See the Routing Table: ip route
$ip route show
# the routing table
default via 192.168.1.1 dev eth0
192.168.1.0/24 dev eth0 ...
# ip route get 8.8.8.8: which route wins# ip -4 route show: IPv4 routes only# ip route show table all: every table
Reading the Routing Table
default: the catch-all route
via: the next hop (gateway)
dev: which interface to use
Routing Table: Other Fields
proto kernel: auto-installed
metric: lower number wins
onlink: skip gateway check
scope link: same L2, no hop
ip route show: Real Output
$ip route show
default via 10.0.0.1 dev eth2 proto kernel metric 35 onlink
# the default route: via gateway 10.0.0.1
10.0.0.0/24 dev eth2 proto kernel scope link metric 291
# the connected subnet: reach these directly
10.0.0.1 dev eth2 proto kernel scope link metric 35
# the gateway's own host route, for onlink
geat
Old English: an opening, gap
gateway
the passage through it
⚠️ No gateway means no path out: only the local network is reachable.
ip route show lists only 192.168.1.0/24, no default line. What can this machine reach?
Answer
Only other devices on its own local network. Nothing outside it: no gateway means no path out.
Questions?
L3: Tracing the Path
Find the Broken Hop: traceroute
Shows every hop along the way
The hop that stops answering
Not installed by default
$ sudo apt install -y traceroute
$ traceroute 8.8.8.8
# each line: one hop, its time
1 192.168.1.1 0.4 ms
2 10.20.0.1 3.1 ms
3 * * *
Find the Broken Hop: traceroute
$sudo apt install -y traceroute
$traceroute 8.8.8.8
# each line: one hop, its time
1 192.168.1.1 0.4 ms
2 10.20.0.1 3.1 ms
3 * * *
# hop #, IP, round-trip time; *** = no reply# traceroute -n 8.8.8.8: skip slow DNS lookups
Check: Which Hop?
traceroute shows hops 1-3 answering, then 4 onward all show *. What failed?
Answer
Hop 4, or the link just past hop 3: everything up to hop 3 is proven reachable.
$ss-tuln# listening TCP/UDP ports
tcp LISTEN 0.0.0.0:22
tcp LISTEN 0.0.0.0:80
# ss -tulnp: also show which process owns it# ss -s: just a summary count, no rows
$dpkg -l netcat-openbsd
# "ii" means installed; "no packages" means missing$sudo apt install -y netcat-openbsd
$nc-zv 10.0.0.50 5432
# -z: scan only, don't send data# -v: verbose, show success or failure
Connection to 10.0.0.50 5432 succeeded!
# nc -zv host 20-25: scan a port range
Layer 4 Commands
#
Command
Example
Purpose
1
ss
ss -tuln
List listening network ports
2
nc
nc -zv 10.0.0.50 5432
Test if an IP + port is reachable
Questions?
L7: Checking DNS
Why DNS Integrity?
A resolve isn't always right
A stale record misdirects
Verify what you actually reach
Resolver Status: resolvectl
Not installed by default
Shows which DNS server is used
Per interface, not just global
$ sudo apt install -y systemd-resolved
$ resolvectl status
# which DNS server, per interface
Link 2 (eth0)
Current DNS Server: 8.8.8.8
DNS Servers: 8.8.8.8
Resolver Status: resolvectl
$sudo apt install -y systemd-resolved
$resolvectl status
# which DNS server, per interface
Link 2 (eth0)
Current DNS Server: 8.8.8.8
DNS Servers: 8.8.8.8
# resolvectl query example.com: resolve one name# resolvectl dns eth0: just that interface's server
$sudo apt install -y curl
$curl-I https://parts.dealer-portal.com
# -I: headers only, no page body
HTTP/1.1 200 OK
Content-Type: text/html
# 200 OK: the app layer responded# curl -v: show the full handshake# curl -s: silent, no progress bar
Check: Right Tool?
You want to confirm a domain actually resolves to an IP, end to end. resolvectl or dig?
Answer
dig. resolvectl shows which server THIS machine would ask; dig actually performs the lookup and shows the answer.
Questions?
L7: Hostname & /etc/hosts
Why Naming Matters
Clones inherit the same name
Alerts become hard to place
Unique names, every machine
Set the Hostname: hostnamectl
Shows or sets the hostname
set-hostname needs sudo
Takes effect without a reboot
$ hostnamectl
# current hostname and OS info
Static hostname: ubuntu-server
$ sudo hostnamectl set-hostname web01
Set the Hostname: hostnamectl
$hostnamectl# current hostname and OS info
Static hostname: ubuntu-server
$sudo hostnamectl set-hostname web01
# --pretty "Web Server 1": a display name only# hostnamectl status: same as the bare command
/etc/hosts: Local Overrides
Checked before real DNS
For a name with no DNS entry
Can cause a silent collision
Check: Which Wins?
/etc/hosts has an entry for api.example.com, and real DNS has a different one. Which wins?
Answer
/etc/hosts. It is checked first, so its entry overrides whatever real DNS would have returned.
Layer 7 Commands
#
Command
Example
Purpose
1
resolvectl
resolvectl status
Show the active DNS resolver
2
hostnamectl
hostnamectl set-hostname web01
View or set this machine's hostname
3
curl
curl -I https://example.com
Test the application layer directly
Questions?
Troubleshooting
Why Method Matters
Guessing wastes bay time
Work outward, layer by layer
Isolate the fault, then fix it
Start With ping
ping already taught, Module 2
Test gateway, then the host
No reply: look closer here
Use Case 1: DB Unreachable
Layer
Check
Result
Meaning
L2
ip link
UP
OK, not the cause
L3
ping gateway
Replies
OK, not the cause
L4
ss -tuln
Port 5432 missing
Database isn't running
L7
skipped
n/a
Found it already, stop here
Use Case 2: Stale DNS
Layer
Check
Result
Meaning
L2
ip link
UP
OK, not the cause
L3
ping gateway
Replies
OK, not the cause
L4
ss -tuln
Port 443 listening
OK, not the cause
L7
resolvectl / curl -I
Resolves to old IP
Stale DNS record
Use Case 3: No Network
Layer
Check
Result
Meaning
L2
ip link
DOWN
Cable unplugged or NIC disabled
L3
skipped
n/a
Found it already, stop here
L4
skipped
n/a
n/a
L7
skipped
n/a
n/a
Use Case 4: Firewall Blocks
Layer
Check
Result
Meaning
L2
ip link
UP
OK, not the cause
L3
ping 10.0.0.50
Replies
OK, server itself is reachable
L4
nc -zv 10.0.0.50 5432
Connection refused
Firewall blocks this port
L7
skipped
n/a
Found it already, stop here
⚠️ ss on the diagnostic terminal can't see this: it only shows local sockets, not whether a remote port is actually reachable over the network.
Questions?
Lab: L2/L3 Config
Scenario: Configure the Server
Kali: your admin workstation
Ubuntu: the diagnostics server
Give it a working static IP
Requirements
A real static IP via netplan
A working default route
A working DNS resolver
Verify Ubuntu's Packages
Confirm ssh server exists
Confirm netplan & DNS exist
Install/start if missing
$ dpkg -l openssh-server netplan.io \
systemd-resolved
# "ii" means installed; "no packages" means missing
$ sudo apt install -y openssh-server \
netplan.io systemd-resolved
# safe to re-run even if already installed
$ sudo systemctl enable --now ssh
# starts sshd now, and on every boot
Verify Ubuntu's Packages
$dpkg-l openssh-server netplan.io \
systemd-resolved
# "ii" means installed; "no packages" means missing$sudo apt install -y openssh-server \
netplan.io systemd-resolved
# safe to re-run even if already installed$sudo systemctl enable --now ssh
# starts sshd now, and on every boot
Kali & Ubuntu Share One IP
Both WSL2 distros, one IP
sshd picks up port 22 first
Give Kali its own port
$ echo 'Port 2222' | \
sudo tee -a /etc/ssh/sshd_config
$ sudo systemctl restart ssh
# still "connection refused" on 22?
# on Ubuntu: sudo systemctl enable --now ssh
⚠️ Skip this and ssh may land on Kali's own banner instead of Ubuntu's: both answer the same IP.
Kali & Ubuntu Share One IP
$ echo 'Port 2222' | \
sudo tee -a/etc/ssh/sshd_config$sudo systemctl restart ssh
# run this on Kali only, once# Ubuntu keeps the default port 22# Kali answers on 2222 instead# still "connection refused" on 22?# on Ubuntu: sudo systemctl enable --now ssh
Clear Any Stale Host Key
Rebuilt VM? Old key remains
ssh refuses to connect
Remove it before sshing in
$ IP=<ubuntu-ip>
$ ssh-keygen -f ~/.ssh/known_hosts -R $IP
# safe to run even if nothing's stale
⚠️ Skipping this is fine until the VM gets rebuilt; then ssh refuses with "Host key verification failed" instead of connecting.
Clear Any Stale Host Key
$ IP=<ubuntu-ip>
$ssh-keygen-f~/.ssh/known_hosts-R $IP
# safe to run even if nothing's stale# removes any old entry for this IP
Still Stuck? Reset WSL
Last resort, not routine
Resets the shared network
Run on Windows, not in WSL
$ wsl --shutdown
# wait ~10 seconds, then reopen both tabs
⚠️ ssh hanging (not refusing) after everything else checks out usually means the shared WSL2 network state itself is stuck, not a service.
Still Stuck? Reset WSL
$wsl--shutdown# wait ~10 seconds, then reopen both tabs# resets the whole shared network stack,# not just one distro
Step 1: Check the Starting Point
See what interface exists now
Note any current address
Note the gateway (ip route)
This is your before picture
$ ssh <username>@$IP
# "username" is literal text, not a $var
$ ip addr show
# note your subnet, e.g. 10.0.0.0/24
$ ip route show
# note "default via X.X.X.X": your gateway
Step 1: Check the Starting Point
$ssh <username>@$IP
# "username" is literal text, not a $var$ip addr show
# note your subnet, e.g. 10.0.0.0/24$ip route show
# note "default via X.X.X.X": your gateway
$ .\enable-mirrored.ps1
# writes .wslconfig, then restarts WSL
Turn On Mirrored Mode
$.\enable-mirrored.ps1# writes .wslconfig, then restarts WSL
Verify: Host's Real IP
Find the host's real IP
WSL will come to share it
$ ipconfig
# find "IPv4 Address" under your
# real Ethernet adapter
Verify: Host's Real IP
$ipconfig# find "IPv4 Address" under your# real Ethernet adapter
Verify: WSL's New IP
Same IP now inside WSL
Mirrored mode is active
$ ip addr show
# the host's IP now appears here too
Verify: WSL's New IP
$ip addr show
# the host's IP now appears here too
Connect the Cable
Plug cable into both laptops
Find the adapter's real name
$ Get-NetAdapter
# lists every adapter and its real name
Connect the Cable
$Get-NetAdapter# lists every adapter and its real name
Assign Static IPs
Same subnet, different host
Partner A: .77.1, B: .77.2
Use your own adapter name
$ .\set-static-ip.ps1 "Ethernet" "192.168.77.1" 24
# Partner A runs this
$ .\set-static-ip.ps1 "Ethernet" "192.168.77.2" 24
# Partner B runs this; same script, own IP
Assign Static IPs
$.\set-static-ip.ps1"Ethernet""192.168.77.1"24# Partner A runs this$.\set-static-ip.ps1"Ethernet""192.168.77.2"24# Partner B runs this; same script, own IP
Confirm the New IP
Re-check with ipconfig
New static IP now showing
$ ipconfig
# your Ethernet adapter now shows
# 192.168.77.x, not the old address
Confirm the New IP
$ipconfig# your Ethernet adapter now shows# 192.168.77.x, not the old address
Ping Across, WSL to WSL
From Partner A's WSL shell
Target: Partner B's new IP
Works: real, shared IP now
$ ping 192.168.77.2
# from Partner A, targeting Partner B
$ ping 192.168.77.1
# from Partner B, targeting Partner A
Ping Across, WSL to WSL
$ping 192.168.77.2
# from Partner A, targeting Partner B$ping 192.168.77.1
# from Partner B, targeting Partner A
Why This Worked
As introduced earlier: NAT
Mirrored: shares host's IP
That's why the ping worked
Heads Up: Mirrored Mode
⚠️ If the ping still fails, confirm the static IP really landed on the
Ethernet adapter the cable is plugged into, not Wi-Fi or a different port;
Get-NetAdapter's own Status column shows which one is really Up.
journald collecting a failed login is one thing. fail2ban blocking the attacker's IP is another. Which is which?
Answer
journald collects; fail2ban reacts. Collecting alone never stops a second attempt from the same attacker.
journalctl, Revisited
Already taught in Module 6
-p err: error priority only
-u sshd: just the ssh service
$ journalctl -p err --since today
# -p err: show only error-level and worse
# --since today: skip everything older
$ journalctl -u sshd
# -u sshd: just the ssh service
journalctl, Revisited
$journalctl-p err --since today
# -p err: show only error-level and worse# --since today: skip everything older$journalctl-u sshd
# -u sshd: just the ssh service
Use Case: journalctl
Service fails, cause unclear
journalctl -u name narrows it
The exact line, timestamped
Use Case: Compliance
Auditor asks who logged in
Already recorded, nothing new
No extra tracking needed
Questions?
Word Origin: "Syslog"
sys + log: a system log
Written 1980 by Eric Allman
For BSD's Sendmail project
Became the standard, 1980–2009
Every log line a modern Linux tool writes still traces back to this 1980 format.
$ date
Fri Oct 16 10:02:15 PDT 2026
$ date-u
Fri Oct 16 17:02:15 UTC 2026
See It: date vs. date -u
$ date# Local time: whatever zone this VM is in
Fri Oct 16 10:02:15 PDT 2026
$ date-u# -u: force UTC output instead
Fri Oct 16 17:02:15 UTC 2026
Why Servers Log in UTC
Avoids DST's repeated hour
Same meaning in every country
Logs from 5 VMs line up
See It: Both Times at Once
One command, two readings
Local time and UTC together
Full command ahead
$ timedatectl
Local time: Fri 2026-10-16 10:02:15 PDT
Universal time: Fri 2026-10-16 17:02:15 UTC
See It: Both Times at Once
$ timedatectl# One call shows local AND UTC
Local time: Fri 2026-10-16 10:02:15 PDT
# Same instant, UTC reference
Universal time: Fri 2026-10-16 17:02:15 UTC
Check: Is GMT Just UTC?
London shows GMT in winter and BST in summer, but a server's logs always say UTC. Are GMT and UTC the same thing?
Only in winter, when both sit at +0. GMT shifts for daylight saving; UTC never does, which is why logs use UTC instead.
A Clock a Few Minutes Off
SSH key auth can silently fail
TLS handshakes get rejected
Distributed logs misalign
Check: Which Fails First?
A VM is 6 hours behind. SSH still works. A website load fails with a certificate error. Why that one first?
TLS certificate validity windows are checked to the second; SSH key auth mostly ignores wall-clock time entirely.
Hospital Case: Cert Fails
Dashboard calls Clinical Data
HTTPS cert checked by time
Clock drift breaks the link
Use Case: Log Order
Situation: 5 VMs, 1 incident
Tool: synced clocks, logs
Result: true event order
NTP & Stratum
NTP & Stratum
Clocks Drift on Their Own
A quartz crystal is not exact
Drift adds up: seconds per day
NTP corrects it continuously
Stratum: Layers of Trust
Stratum 0: atomic clocks, GPS
Stratum 1: directly wired
Your VM: stratum 3 or 4
Check: Why Not Stratum 1?
Every stratum-1 server is directly wired to a real reference clock. Why not just point every VM at one?
A handful of stratum-1 servers cannot answer millions of clients; the stratum tree spreads that load.
Check: Does Attacker Count?
The Attacker VM is on your shared network but is not your team's to configure. Does its clock still need to agree with yours?
Yes: every VM on the class network points at the same public pool, so even another team's timestamps stay comparable to yours.
Checking the Time
Checking the Time
date: The Simple Check
Plain, no flags, prints now
Shows local time and zone
$ date
Fri Oct 16 10:02:15 PDT 2026
date: The Simple Check
$ date# No flags: just the current time
Fri Oct 16 10:02:15 PDT 2026
timedatectl: Full Picture
Shows local, UTC, sync state
NTP service: active or not
$ timedatectl
Local time: Fri 2026-10-16 10:02:15 PDT
Universal time: Fri 2026-10-16 17:02:15 UTC
NTP service: active
timedatectl: Full Picture
$ timedatectl# Local time, zone, and NTP state
Local time: Fri 2026-10-16 10:02:15 PDT
# NTP service: active means synced
NTP service: active
Check: date vs. timedatectl
date just prints a timestamp. timedatectl prints a whole status block. When would you reach for date instead?
Inside a script that only needs the current value, not a human status report: date is simpler to parse.
Use Case: Confirm Trust
Backup log says 2:00 AM
Incident report says 5:00 AM
timedatectl finds the bug
Setting the Time Zone
Setting the Time Zone
Time Zone: A Named Offset
/usr/share/zoneinfo holds them
Region/City, not just a number
Handles daylight saving too
Setting the Zone
Takes a Region/City name
list-timezones shows all zones
$ timedatectlset-timezoneAmerica/Los_Angeles
Setting the Zone
$ timedatectllist-timezones | grepLos_Angeles# Find the exact zone name first
America/Los_Angeles
$ timedatectlset-timezoneAmerica/Los_Angeles# Then set it; takes effect right away
Check: Why a Name?
A zone could just be stored as "UTC-7". Why does Linux use "America/Los_Angeles" instead?
A fixed offset breaks every daylight-saving switch; a named zone carries the whole rule set for that region.
chrony: Staying in Sync
chrony: Staying in Sync
chrony: A Background Daemon
Installed, running by default
Talks to pool servers over NTP
Nudges the clock continuously
chronyc tracking: Synced?
Shows the current offset
Last offset: how far off
$ chronyctracking
Reference ID : A29FC87B
System time : 0.000012 seconds fast
chronyc tracking: Synced?
$ chronyctracking# Reference ID: which server it trusts
Reference ID : A29FC87B
# System time: current drift, in seconds
System time : 0.000012 seconds fast
$ sudohwclock--show# Reads straight from the battery-backed clock
2026-10-16 10:02:11.293211-07:00
$ sudohwclock--systohc# Copies the now-synced system time to it
Check: Sync Hardware Too?
chrony already keeps the system clock correct while Linux is running. Why also fix the hardware clock?
The hardware clock is what the next boot starts from, before chrony has had any time to correct it.
Use Case: Snapshot Jump
VM restored from old snapshot
hwclock + chrony re-sync it
Logs trust real time again
Word Origin: "Stratum"
Latin: a layer, spread out
Geology: rock layers, stacked
NTP borrows it for trust
Word Origin: "GMT"
Greenwich: a London borough
Mean: an average solar day
Royal Observatory set it
Word Origin: "Epoch"
Greek: epokhe, a fixed point
Unix epoch: Jan 1, 1970, UTC
Every timestamp counts from it
Practice Lab
Practice Lab
Scenario: The Drifting VM
A VM sat suspended for a week
Its clock is now badly wrong
Fix it, then prove it stuck
Step 1: Current Status
See the drift before fixing it
Confirm NTP service state
$ timedatectl
Step 1: Current Status
$ timedatectl# Note the current local time and zone
Step 2: Set Correct Zone
Set America/Los_Angeles
$ timedatectlset-timezoneAmerica/Los_Angeles
Step 2: Set Correct Zone
$ timedatectlset-timezoneAmerica/Los_Angeles# Takes effect immediately, no reboot
Step 3: chrony Is Running
Install it if missing
Then check its service state
$ sudoaptinstall-ychrony$ systemctlstatuschrony
Step 3: chrony Is Running
$ sudoaptinstall-ychrony# Not installed by default on every image$ systemctlstatuschrony# Confirm it is active and running
Step 4: Watch It Re-Sync
Offset shrinks over checks
Run it more than once
$ chronyctracking | grepSystem time
Step 4: Watch It Re-Sync
$ chronyctracking | grepSystem time# Re-run after a minute: offset should shrink
Step 5: A Trusted Source
Look for the * marker
Means a source is now trusted
$ chronycsources
Step 5: A Trusted Source
$ chronycsources# ^* on a row means it is now trusted
Check: Proving It Worked
A screenshot of timedatectl right after the fix looks correct. Why is that not proof the sync held?
A one-time correct reading could be luck; chronyc tracking showing a shrinking offset over time is the real proof.
Deliverable
Correct time zone set
chrony installed and running
chronyc tracking: synced
$ chronyctracking
System time : 0.000031 seconds fast
$ cat/opt/hospital-vm/legacy-notify.sh#!/bin/bash# TODO: retire, replaced by new pipeline# patient1 / Patient123!echo "legacy notify: disabled"$ ls-l/opt/hospital-vm/legacy-notify.sh-rw-r--r-- 1 root root 118 legacy-notify.sh# an accurate audit would flag this
Join the Hospital VM
Clone the shared repo
Run setup.sh
Confirm SETUP OK
$ sudoaptinstall-ygit# not installed by default$ gitclone\https://github.com/SE4CPS/2026-COMP-175.git$ cd 2026-COMP-175/project/part-2/Hospital-VM
$ chmod+x setup.sh
$ ./setup.shSETUP OK
Q1: Unknown Clock State
New VM, unknown state
Can't trust logs blindly
Check status first
A wrong clock makes a log entry timestamped 10:42 actually be from an hour earlier: Monitor Read/Write can't correlate a dashboard alert with the real event until the clock is proven reliable.
Q1: What's the Clock State?
Before trusting any log timestamp, what command shows the current time, zone, and NTP service state?
$ timedatectl
Local time: ...
Time zone: ...
NTP service: active
Answer: timedatectl
Shows local time & zone
Shows NTP service state
The starting diagnostic
$ timedatectl | grep"NTP service"
NTP service: active
Q2: Zone Set, But Synced?
A zone can look correct
That's not the same as
actually being synced
A VM suspended for days can still report "America/Los_Angeles" correctly while having drifted underneath: the dashboard would show stale or out-of-order events without this check.
Q2: Is It Actually Synced?
A zone can be set correctly while the clock is still unsynced. What confirms real sync, not just a zone?
Without chrony actually running, nothing corrects drift over time: a clock can drift minutes per week, enough to make two near-simultaneous log entries appear out of real order on the dashboard.
Q3: Install and Confirm chrony
chrony isn't installed by default. What two commands install it and confirm its service is running?
$ sudoaptinstall-ychrony# not installed by default$ sudosystemctlenable--nowchrony# enable on boot + start now$ systemctlstatuschrony
Active: active (running)
Answer: install, then status
apt install -y chrony first
systemctl status confirms
active (running) is the goal
$ systemctlis-activechrony
active
Q4: Running, But How Far Off?
chrony running isn't
the same as synced tight
Check the real offset
Confirms how accurate the sync really is, not just that it's turned on: a sub-second offset proves the dashboard can tell which of two near-simultaneous reads happened first.
Q4: Check the Sync Offset
chrony is running. What command shows exactly how far off the system clock currently is?
$ chronyctracking
System time : 0.000031 seconds fast
Answer: chronyc tracking
System time line is key
A shrinking offset = good
Re-check after a minute
$ chronyctracking | grep"System time"
System time : 0.000031 seconds fast
Q5: Which Source Is Trusted?
Several NTP sources
Only one is trusted
Look for the marker
Shows where the time is actually coming from: a compromised or misconfigured NTP source could skew the clock deliberately, making the activity log's event order unreliable.
Q5: Confirm the Trusted Source
Several NTP sources are configured. Which command shows which one is actually trusted right now?
simulate.sh logs human-readable timestamps, but other tools like databases and APIs often log raw epoch numbers: converting one lets you cross-reference a database transaction with a specific logged read event.
Q6: Convert an Epoch Timestamp
clinical-activity.log logs a raw epoch timestamp. What command converts it to a readable date?
$ date-d@1730000000
Mon Oct 27 ... 2026
Answer: date -d @epoch
-d @epoch reads seconds
Converts to local time
Lets you compare to now
$ date-d@1730000000+%F_%T
2026-10-27_14:13:20
Epoch's Reference Zone
Q:date -d @0 prints "Dec 31, 1969 4:00 PM PST," not Jan 1, 1970. Whose midnight does epoch 0 actually use?
A: UTC's own midnight: epoch 0 is 1970-01-01 00:00:00 UTC exactly, since UTC is the reference zone itself, not an offset from another one. PST's −8h offset just shifts the local display back across the date line; the underlying epoch number never changes.
Q7: One Zone for Every Team
Different VMs, different
zones means logs never
line up across teams
If every team's VM uses a different zone, the same real event looks like it happened at different times on different dashboards: Monitor Write's backup logs and Monitor Read's access logs must agree on wall-clock time to line up a write with a suspicious read.
Q7: Set a Shared Time Zone
Every team's clock needs the same zone so logs line up. What command sets it?
$ timedatectlshow-pTimezone--valueAmerica/Los_Angeles# proves the zone change stuck$ timedatectl | grep"Time zone"
Time zone: America/Los_Angeles
Q8: Will It Survive a Reboot?
System clock is correct
Hardware clock separate
Write it before reboot
VMs get rebooted, for example after a security update; if the hardware clock wasn't written, the VM could boot with a stale time until chrony catches up, mistiming the first few minutes of log entries after every reboot.
Q8: Survive a Reboot
The system clock is now correct. What command makes sure it is still correct after a reboot?
$ sudohwclock--systohc# writes time to the hw clock
Answer: hwclock --systohc
Writes system to hw clock
hwclock alone reads it back
Confirms it actually stuck
$ hwclock
2026-10-27 14:13:21.123456-07:00
Q9: UTC or GMT?
Two names, not synonyms
Only one never shifts
DST ends this weekend
If this VM's zone were casually labeled GMT instead of UTC, every dashboard timestamp would be off by one hour for roughly seven months a year while the UK observes British Summer Time.
Q9: UTC or GMT?
This weekend (Nov 1), US clocks "fall back" for the end of Daylight Saving Time, so 1:30 AM happens twice in local time. For this VM's clock, would you recommend UTC or GMT, and why?
$ sudotimedatectlset-timezoneUTC# UTC never shifts for daylight saving
Answer: UTC, Not GMT
GMT ~ UK winter clock only
BST (UTC+1) runs Mar-Oct
UTC is the one fixed point
$ timedatectlshow-pTimezone--valueUTC# confirms it stuck: never GMT$ timedatectl | grep"Time zone"Time zone: UTC
Deliverable
Zone set correctly
chrony installed & synced
Trusted source confirmed
hwclock written
$ chronyctracking
System time : 0.000031 seconds fast
$ cat/opt/hospital-vm/legacy-notify.sh#!/bin/bash# TODO: retire, replaced by new pipeline# patient1 / Patient123!echo "legacy notify: disabled"$ ls-l/opt/hospital-vm/legacy-notify.sh-rw-r--r-- 1 root root 118 legacy-notify.sh# an accurate audit would flag this
Join the Hospital VM
Clone the shared repo
Run setup.sh
Confirm SETUP OK
$ sudoaptinstall-ygit# not installed by default$ gitclone\https://github.com/SE4CPS/2026-COMP-175.git$ cd 2026-COMP-175/project/part-2/Hospital-VM
$ chmod+x setup.sh
$ ./setup.shSETUP OK
Q1: Clock State Before the Audit
Audit about to start
Clock state unknown
Check it first
The audit's whole job is to say when access happened: if this VM's own clock state is unverified going in, every timestamp the audit later relies on is suspect before a single file is even checked.
Q1: What's the Clock State?
Before auditing any file timestamp, what command shows the VM's current time, zone, and NTP state?
$ timedatectl
Local time: ...
Time zone: ...
NTP service: active
Answer: timedatectl
Shows local time & zone
Shows NTP service state
Starting point for the audit
$ timedatectl | grep"NTP service"
NTP service: active
Q2: One Zone for the Audit
Wrong zone on this VM
Audit timestamps mislead
Fix the zone first
If this audit VM's zone doesn't match the rest of the fleet, a finding like "patient1 read a record at 2:00 PM" could actually describe an event an hour earlier or later than every other machine's logs.
Q2: Set the Audit's Time Zone
Audit timestamps need to match the rest of the class. What command sets the correct zone?
$ timedatectlshow-pTimezone--valueAmerica/Los_Angeles# proves the zone change stuck$ timedatectl | grep"Time zone"
Time zone: America/Los_Angeles
Q3: Is chrony Even Installed?
chrony is not installed
No real sync without it
Install it, then check
An audit that trusts file timestamps without confirming the auditing machine itself keeps accurate time is building its findings on an unverified assumption: install and enable chrony before trusting anything it reports.
Q3: Install and Confirm chrony
Assume chrony isn't installed on this VM. What two commands install it and confirm it's running?
$ sudoaptinstall-ychrony# not installed by default$ sudosystemctlenable--nowchrony# enable on boot + start now$ systemctlstatuschrony
Active: active (running)
Answer: install, then status
apt install -y chrony first
systemctl status confirms
active (running) is the goal
$ systemctlis-activechrony
active
Q4: Offset Before Trusting mtime
chrony running isn't
proof of a tight offset
Check it before trusting
If this VM's own clock is still seconds or minutes off, the audit could misjudge the order of two closely timed events, like a backup write versus a suspicious read it's meant to flag.
Q4: Check the Sync Offset
Before trusting any file's mtime, what command shows exactly how far off this clock is?
$ chronyctracking
System time : 0.000031 seconds fast
Answer: chronyc tracking
System time line is key
Small offset = trustworthy
Big offset = investigate
$ chronyctracking | grep"System time"
System time : 0.000031 seconds fast
Q5: Which Source Is Trusted?
Several NTP sources
Only one is trusted
Look for the marker
The audit record should name which source the clock actually trusted, not just that some source existed: a rogue or misconfigured source could have skewed the clock the audit itself relied on.
Q5: Confirm the Trusted Source
For the audit record, which command shows which NTP source is actually trusted right now?
A leftover credential in an old script like legacy-notify.sh is only a real finding if you can prove how long it's actually been sitting there: that means comparing its file date against a trustworthy "now."
Q6: Sanity-Check a File's Age
You need to know how old legacy-notify.sh's leftover credential really is. What shows "now" to compare?
$ date
Tue Oct 27 14:13:20 PDT 2026
# compare this to the file's mtime
Answer: date
Shows the current time
Compare to stat's mtime
Confirms the real age
$ date+%F_%T
2026-10-27_14:13:20
Q7: A Stale Hardware Clock?
VM sat suspended a week
Hardware clock may be
stale too, not just drift
A VM that sat suspended for a week could resume with a hardware clock still showing last week's date: any file timestamp checked before chrony catches up would be auditing against a clock that hasn't caught up yet either.
Q7: Rule Out a Stale Hardware Clock
This VM sat suspended for a week. What command checks whether the hardware clock itself is stale?
An auditor signing off needs one final, re-run confirmation that zone, sync, and NTP state all still hold, not just a memory of having checked each one separately earlier in the audit.
Q8: Final Re-Verification
Every clock check has now passed. What single command gives the final summary to sign off the audit?
$ timedatectl
Local time: 2026-10-27 14:13:20 PDT
Time zone: America/Los_Angeles
NTP service: active
Answer: timedatectl
Zone: America/Los_Angeles
NTP service: active
Audit timestamps now trusted
$ timedatectlshow-p \
NTPSynchronized--value
yes
Q9: UTC or GMT?
Audit needs one fixed clock
GMT shifts with UK summer
DST ends this weekend
An audit report dated in GMT would quietly shift by an hour for seven months of the year as the UK moves to British Summer Time: UTC is the one label that never moves, so the audit's own record stays fixed.
Q9: UTC or GMT?
This weekend (Nov 1), US clocks "fall back" for the end of Daylight Saving Time, so 1:30 AM happens twice in local time. For the audit's own timestamps, would you recommend UTC or GMT, and why?
$ sudotimedatectlset-timezoneUTC# UTC never shifts, GMT often does
Answer: UTC, Not GMT
GMT ~ UK winter clock only
BST (UTC+1) runs Mar-Oct
UTC is the audit's one anchor
$ timedatectlshow-pTimezone--valueUTC# confirms it stuck: never GMT$ timedatectl | grep"Time zone"Time zone: UTC
Q10: Trusting a Backup's Timing
Cron job backs up nightly
Audit trusts clock first
Then trusts the schedule
A cron line only means something once the clock it runs against is trusted: now that the audit has verified the clock, the next claim to check is whether the backup job actually fires on the schedule it claims, not just assume the line is real.
Q10: Confirm the Backup Schedule
An auditor is told a backup job runs nightly at 2 AM. What command shows the real cron schedule, to confirm this claim?
$ crontab-l0 2 * * * /opt/hospital-vm/backup.sh
Answer: crontab -l
5 fields: min hr day mo wk
0 2 * * * = 2 AM daily
Backup time now confirmed
$ crontab-l0 2 * * * /opt/hospital-vm/backup.sh# min hr day month weekday
Q11: Did the Timer Fire on Time?
Timer logs LAST and NEXT
Compare to the interval
Drift reveals a problem
A systemd timer whose last run has drifted from its own interval can mean a missed run, or that this VM's clock was wrong the last time it fired: the audit needs to see that run time directly, not assume the timer is healthy.
Q11: Check the Timer's Run Time
The backup should fire at 2 AM daily. What command shows every systemd timer's next (and last) run time?
$ systemctl list-timers
NEXT LEFT UNIT
02:00 9h58m backup.timer
Answer: systemctl list-timers
LAST: when it last fired
NEXT: next scheduled run
Matches cron's own time
$ systemctl list-timers
NEXT LEFT UNIT
02:00 9h58m backup.timer
# LAST column (trimmed) shows# the previous actual run
Q12: Scanning the Log for Sync
Clock and backup both good
Check log for sync errors
Clean now isn't forever
A clean chronyc tracking and crontab -l only describe this moment: a past drift event may already be recorded earlier in the system log, so the audit's last step reads that log, filtered to sync warnings, before signing off.
Q12: Search the Log for Drift
chronyc tracking looks clean right now. What command shows the system log, filtered to warnings and errors, to check for a past sync problem?
$ sudojournalctl-pwarning\--since"2026-10-01"# then pipe to: grep -i sync
$ ipcalc 192.168.1.0/24
# Network: the subnet's own base address
Network: 192.168.1.0/24
# HostMin/HostMax: the usable address range
HostMin: 192.168.1.1
HostMax: 192.168.1.254
Check: Why Not Always /24?
A /24 gives 254 usable hosts. Why would a network ever use a smaller subnet, like a /28?
A smaller subnet limits broadcast traffic and blast radius per segment, even when far fewer than 254 hosts exist.
VLANs
VLANs
Separate Without New Wiring
A tag on each Ethernet frame
One switch, many logical nets
Devices on different VLANs
Check: VLAN vs. Subnet
This module teaches both subnets and VLANs. Are they two names for the same idea, or different layers?
Different layers: a VLAN separates traffic at layer 2 (the switch); a subnet is a layer-3 IP addressing boundary.
Deployment Environments
Deployment Environments
Three Stages of Trust
dev: your own machine
staging: a real copy, checked
production: real users
Check: Deploy to Prod?
A change already works on dev. Why add a staging step before it reaches production at all?
dev often differs from the real environment; staging catches integration issues before real users are affected.
A Real Deploy Script
A Real Deploy Script
Reusing What You Learned
git clone/pull: Module 2
rsync: Module 5
Wrapped in a script: Module 11
deploy.sh: Pull, Then Sync
cd into the repo, pull first
rsync to the staging server
#!/bin/bash
cd /home/user/app && git pull
rsync -avz /home/user/app/ staging:/srv/app/
deploy.sh: Pull, Then Sync
#!/bin/bash
# Always pull the latest before syncing
cd /home/user/app && git pull
# -avz: archive mode, verbose, compressedrsync -avz /home/user/app/ staging:/srv/app/
Check: Why pull First?
The script runs git pull before rsync, not the other way around. Why does the order matter here?
rsync copies whatever is currently on disk; pulling first ensures that copy actually includes the latest code.
Practice Lab
Practice Lab
Scenario: Plan, Then Deploy
Calculate a subnet with ipcalc
Write and run a deploy script
Verify the files arrived
Step 1: Plan the Subnet
A /28 for the registrar team
$ ipcalc 10.0.5.0/28
Step 1: Plan the Subnet
$ ipcalc 10.0.5.0/28
# Confirms 14 usable addresses fit the team
Step 2: Write deploy.sh
Reuses Module 11's own pattern
#!/bin/bash
cd ~/app && git pull
rsync -avz ~/app/ staging:/srv/app/
Step 2: Write deploy.sh
#!/bin/bash
# Same pull-then-sync order as before
cd ~/app && git pull
rsync -avz ~/app/ staging:/srv/app/
Step 3: Run and Verify
chmod +x, run it, then confirm
$ chmod +x deploy.sh$ ./deploy.sh$ ssh staging ls /srv/app/
Step 3: Run and Verify
$ chmod +x deploy.sh$ ./deploy.sh# ssh + ls confirms the files really arrived$ ssh staging ls /srv/app/
Check: Proving It Worked
Step 3's final ls runs on the staging server, not the local machine. Why check there instead of locally?
rsync could have silently failed; checking the remote side is the only real proof the deploy actually worked.
In a Type 2 setup such as VirtualBox on a Windows laptop, which one is the host?
A. The Linux guest OS running inside the VM B. The hypervisor program itself, VirtualBox C. The Windows PC that VirtualBox runs on D. The virtual network switch for the VMs
Answer: C
The Windows PC is the host; VirtualBox is the hypervisor running on it, one layer above the guest.
Other Type 2 hypervisors:
VMware Workstation
Parallels Desktop
Q2
What does sudo apt-get update do?
A. Installs every pending package upgrade B. Refreshes the package lists from repos C. Removes any package no longer used D. Upgrades the kernel to a newer version
Answer: B
update only re-syncs the local package index. Installing is a separate command.
apt-get upgrade: installs them
apt-get install pkg: adds one
apt-get remove pkg: removes it
Q3
What does nmap -p 22 host do?
A. Logs in to host over SSH as root user B. Blocks port 22 on the host's own firewall C. Prints the full routing table of the host D. Checks if port 22 is open on the host
Answer: D
-p 22 scopes the scan to one port; nmap only probes and reports state.
nmap -p 80 host: just port 80
nmap -p 1-1000 host: a range
nmap -sV host: version detect
Q4
After chmod 640 notes.txt, what does ls -l show for its permissions?
A. rw-r----- B. rwxr----- C. rw-rw-r-- D. r--r--r--
Answer: A
640 = 6 (owner: rw-), 4 (group: r--), 0 (other: ---); no execute bit for anyone.
chmod 755: rwxr-xr-x
chmod 600: rw-------
chmod 644: rw-r--r--
Q5
What does sudo ufw allow 22/tcp do?
A. Shuts port 22 in the firewall B. Opens port 22 in the firewall C. Moves SSH onto port 22 now D. Lists every firewall rule in use
Answer: B
allow adds a rule permitting that port/protocol; it never touches sshd's own config.
ufw deny 23/tcp: blocks telnet
ufw allow 80/tcp: opens HTTP
ufw status: lists the rules
Q6
What makes a file hidden from a plain ls?
A. Its name has no file extension B. Its owner is the root user now C. Its name starts with a dot (.) D. Its permission mode is set 000
Answer: C
A leading dot is purely a naming convention; ls -a still lists it.
Hidden by convention:
.bashrc
.ssh/
.gitignore
Q7
Which of these is NOT stored in a file's inode?
A. The owner and group IDs of the file B. The permission mode bits of the file C. The name shown for the file in ls -l D. The time the file was last modified
Answer: C
A filename lives only in a directory entry; the inode never stores it.
What an inode DOES store:
uid/gid, mode bits
size, timestamps, data blocks
Q8
What does id do?
A. Shows your uid, gid, and groups B. Shows this machine's IP address C. Changes the numeric user ID now D. Lists every account on a system
Answer: A
id reports the identity the current shell is running as.
Example output:
uid=1000(alex) gid=1000(alex)
groups=1000(alex),27(sudo)
Q9
According to the FHS, where do system log files belong?
A. /etc/log B. /usr/log C. /tmp/log D. /var/log
Answer: D
/var holds data that changes at runtime; /etc is only for static config.
/var/log/syslog
/var/log/auth.log
/var/log/apt/history.log
Q10
After chmod 2770 /srv/registrar, what does the leading 2 (setgid) do?
A. Only root may remove files inside it B. Any new file inside inherits its group C. Every file inside is marked executable D. The folder gets hidden from a plain ls
Answer: B
setgid on a directory makes every new file inherit the directory's own group.
A file made by any user shows:
shows group: registrar
Q11
What does sudo -u www-data whoami do?
A. Runs whoami as www-data, prints that B. Runs whoami as root, and prints root C. Switches your shell over to www-data D. Creates a new account named www-data
Answer: A
-u names the target user for this one command only; the shell's own identity never changes.
sudo -u postgres psql
sudo -u backup tar -czf ...
Q12
What does inotifywatch -e create,modify /srv/registrar do?
A. Streams every event, with no summary B. Deletes every new file as it appears C. Changes the folder's permission bits D. Prints a summary table of the events
Answer: D
inotifywatch is the summary tool in inotify-tools, unlike inotifywait's live stream.
Example summary row:
3 CREATE, 1 MODIFY report.txt
Q13
Which best defines a process?
A. A file saved on disk, waiting to be run B. A program that is running, with a PID C. A user account that owns some files D. A network port that a service listens on
Answer: B
A program is the file on disk; a process is that program running, with its own PID.
/usr/sbin/sshd: the program
PID 842: sshd now running
Q14
Why run top instead of ps aux?
A. top shows just the root user's processes B. top prints the full command line of each one C. top keeps refreshing the process list live D. top also lists processes on other hosts
Answer: C
ps aux is one static snapshot; top redraws continuously in real time.
top's live columns:
%CPU, %MEM, refreshed live
Q15
What does ssh-keygen -t ed25519 do?
A. Makes a brand-new SSH key pair B. Copies your public key to a server C. Deletes your existing SSH key pair D. Opens an SSH session to a host
Answer: A
ssh-keygen generates a new key pair; -t picks the algorithm. Copying is ssh-copy-id's job.
Files it creates:
id_ed25519 (private)
id_ed25519.pub (public)
Q16
Which order matches: a file on disk, that file running with a PID, a process managed by systemd?
A. Process, program, service B. Service, process, program C. Program, service, process D. Program, process, service
Answer: D
Program (on disk) becomes a process (running, PID), which systemd manages as a service.
/usr/sbin/sshd: the program
PID 842: the process
ssh.service: the service
Q17
What does sudo systemctl restart cron do?
A. Stops and then starts cron right now B. Makes cron start up at each future boot C. Shows if cron is currently running D. Deletes the unit file that runs cron
Answer: A
restart stops then starts the service now; it changes nothing about boot-time behavior.
systemctl enable: on at boot
systemctl reload: re-reads cfg
Q18
In a crontab, what does 0 6 * * 1-5 mean?
A. Every 6 minutes, around the clock B. 6:00 AM, Monday through Friday C. 6:00 PM, every day of every week D. Midnight, every day of every week
Answer: B
Fields are minute hour day month weekday: 6:00 AM, Mon-Fri only.
*/15 * * * *: every 15 min
0 0 1 * *: midnight, month 1
Q19
A file /srv/library/catalog.txt has one hard link named /srv/library/backup.txt and one symlink named /srv/library/latest.txt pointing at it. Draw and label a diagram showing how the directory entries, the inode(s), the data blocks, and the symlink relate.
Q20
The registrar's Ubuntu server runs a nightly backup script, but last night it did not run, and a colleague says the server "was slow all evening." From your Kali VM you can SSH in. Write the steps you would take, naming the command for each and why.
Q1: Role of a Sysadmin
Explain the sysadmin role
Name one history milestone
Include its year
Manages systems and servers
Handles accounts and security
1950s: Computer Operators
ran mainframes by hand
Source: Module 1 slides (The Sysadmin Role timeline)
End every answer with one line:
AI used: No
AI used: Yes, asked how
-mtime counts days;
wrote the answer myself
Modules 3 and 4: 10 questions each, 5 conceptual and 5 practical
Homework 3, Q1: What Is an Inode?
What does an inode store?
What does it not store?
Why can data outlive a name?
Source: class slides (Module 3)
Answer
Stores metadata (owner, perms, size, timestamps, block locations), not the filename. The name lives in a directory entry. Data survives if a hard link or open handle still references the inode.
Homework 3, Q2: Symlink vs. Hard Link
Compare the two link types.
The original file is deleted.
What happens to each link?
Source: class slides (Module 3)
Answer
Hard link: another name for the same inode; still works after the original name is deleted. Symlink: a stored path to the original; becomes broken once the original is deleted.
Homework 3, Q3: Everything Is a File
What does the phrase mean?
Give 2 non-document examples
Why does it help an admin?
Source: class slides (Module 3)
Answer
/dev/null (a device) and /proc/cpuinfo (kernel info) are both accessed as files. This lets an admin use the same commands and permissions model to manage very different system resources.
Homework 3, Q4: x on Directory vs. File
What does x mean on a folder?
What does x mean on a file?
How do the two differ?
Source: class slides (Module 3)
Answer
On a directory: x lets you traverse/enter it (access a known item by name), but not by itself list its contents. On a file: x lets you execute it as a program or script.
Homework 3, Q5: setgid and Sticky Bit
Folders set to 2770 and 3770
What does setgid add?
What does sticky add?
Why do both help sharing?
Source: class slides (Module 3)
Answer
Both give owner+group rwx, others none. setgid (2770): new files inherit the folder's group. Sticky (added in 3770): only the owner or root can delete/rename another member's files.
Homework 3, Q6: Find Old Files
Look in /srv/library
Regular files only
Not modified in 6 months
Explain the number you used
Source: class slides (Module 3)
Answer
find /srv/library -type f -mtime +180. -type f selects regular files; 180 approximates 6 months in days.
Homework 3, Q7: Create a Team Folder
Create /srv/team
Only group team gets access
Group can read, write, enter
New files inherit the group
Source: class slides (Module 3)
Answer
sudo mkdir -p /srv/team; sudo chown root:team /srv/team; sudo chmod 2770 /srv/team. Owner+group rwx, others none, setgid for group inheritance.
Homework 3, Q8: Disk Usage
Which disk holds /srv?
How full is that disk?
Use human-readable sizes
Source: class slides (Module 3)
Answer
df -h /srv
Homework 3, Q9: Links to report.txt
Make one symbolic link
Make one hard link
Show proof of shared inode
Source: class slides (Module 3)
Answer
ln -s report.txt report-symbolic.txt; ln report.txt report-hard.txt; ls -li report.txt report-hard.txt. Matching inode numbers prove the hard link shares the inode.
Homework 3, Q10: Add a User to a Group
Add dana to group library
Keep her other groups
Then verify her group list
Source: class slides (Module 3)
Answer
sudo usermod -aG library dana; id -nG dana. -aG appends without removing her existing groups.
Homework 3, Q11: DAC, RBAC and MAC
Define each in one sentence
Which one is chmod?
Why can root be denied?
Source: class slides (Module 4)
Answer
DAC: owner decides access. RBAC: access depends on assigned role. MAC: a system-wide policy controls access. chmod = DAC. Root can still be denied under MAC since it's enforced independent of DAC ownership.
Homework 3, Q12: Least Privilege
What is least privilege?
One sudoers script vs. ALL
Why is one script safer?
Source: class slides (Module 4)
Answer
Grant only the access needed for the job. One script in sudoers limits what can run as root; ALL lets any command run as root, so a mistake or compromise can affect the whole system.
Homework 3, Q13: AAA in Practice
Authentication, authorization
and accounting: real examples
If one is absent, what's lost?
Source: class slides (Module 4)
Answer
Authentication: an SSH login, in /var/log/auth.log. Authorization: a sudoers rule. Accounting: the sudo log entry. Missing one leaves no record of who connected, what was allowed, or what was done.
Homework 3, Q14: inotifywait Log Lines
What can a log line tell you?
What can it not tell you?
Give 2 limits that matter
Source: class slides (Module 4)
Answer
Shows the watched path, event type, and (if configured) a timestamp. It does NOT show who or which process caused it, and can miss events from unwatched paths, downtime, or queue overflow.
Homework 3, Q15: The ACL Mask
What is the ACL mask?
How can it cancel a grant?
Source: class slides (Module 4)
Answer
Caps the effective permissions for named users/groups and the owning group (not the owner or other). A setfacl grant can be silently reduced by the mask; getfacl shows the actual effective permission.
End every answer with one line:
AI used: No
AI used: Yes, asked how
-mtime counts days;
wrote the answer myself
Modules 5 and 6: 5 conceptual questions each, no code required
Homework 4, Q1: Process vs. Program
What is a program, on disk?
What is a process, once run?
Use a car diagnostic scan as the example
Source: class slides (Module 5)
Homework 4, Q2: One-Time vs. Live View
Compare ps and top.
ps: a snapshot. top: live.
When use top during a test?
Source: class slides (Module 5)
Homework 4, Q3: Foreground vs. Background
What can a bg job let you do?
Why background the logger?
What does jobs show you?
Source: class slides (Module 5)
Homework 4, Q4: Why Lower a Job’s Priority?
What does nice change?
Why lower its priority
during a real-time dyno test?
Source: class slides (Module 5)
Homework 4, Q5: Why Keys Beat Passwords
Why is key-based SSH stronger?
What is the public key for?
What is the private key for?
Source: class slides (Module 5)
Homework 4, Q6: Starting vs. Enabling
What does starting it do?
What does enabling it add?
Why enable it too?
Source: class slides (Module 6)
Homework 4, Q7: Timer or Plain Cron?
What can a systemd timer do
that plain cron cannot?
When would a shop prefer each?
Source: class slides (Module 6)
Homework 4, Q8: Why Restart=on-failure?
What does this setting do?
It watches a sensor
that can disconnect sometimes
Source: class slides (Module 6)
Homework 4, Q9: Five Fields, One Real Job
Name cron’s five time fields
Check tires every 15 min
Write the full crontab line
Source: class slides (Module 6)
Homework 4, Q10: Why Cron Needs Full Paths
Why does cron need full paths?
Using a relative path instead
What mistake could that cause?
Source: class slides (Module 6)
Lab 4: Shop Diagnostics Server
Kali = admin workstation
Ubuntu VM = diagnostics server
All of Q2–Q10 run over SSH
Show your prompt in each shot
State AI use on each answer
Lab 4, Q1: SSH In & Get the Files
SSH from Kali into Ubuntu
Rest of lab runs on Ubuntu
Clone repo, chmod the scripts
# from Kali
$ ssh USER@UBUNTU_IP
# now on Ubuntu:
$ git clone \
https://github.com/SE4CPS/2026-COMP-175.git
$ cd 2026-COMP-175/modules/homework-4
$ chmod +x *.sh
$ ls
Evidence
Kali prompt, then ssh
The Ubuntu prompt after login
ls showing .sh files, csv
Screenshot from: Kali and Ubuntu
Lab 4, Q2: Run and Identify a Process
Run engine-scan.sh (fg)
In a 2nd shell, find its PID
Use pgrep, not ps | grep
$ ./engine-scan.sh
# in a second ssh session to Ubuntu:
$ pgrep -f engine-scan.sh
Evidence
The scan’s RPM/temp output
pgrep showing a real PID
Screenshot from: Kali and Ubuntu
Lab 4, Q3: Background, Confirm, Foreground
Start the logger in the bg
Confirm it’s running with jobs
Bring to fg, then stop it
$ ./telemetry-logger.sh &
$ jobs
$ fg
# Ctrl+C to stop it
Evidence
jobs shows the logger
Prompt after fg, then Ctrl+C
Screenshot from: Kali and Ubuntu
Lab 4, Q4: Stop a Running Job
Start dyno-test.sh in the bg
Find its PID, send it SIGTERM
Confirm the process is gone
$ ./dyno-test.sh &
$ pgrep -f dyno-test.sh
$ kill PID
$ pgrep -f dyno-test.sh
# no output: it is gone
What did you build: which two VMs, and how are they networked?
I used two personal VirtualBox VMs: admin-ws (Kali) as the admin workstation, and hospital-records (Ubuntu) as the server. They communicate on an isolated host-only network, never bridged, with no real patient data.
Q2: Records Permissions
What permission changes did you make on the records directory and files, and why?
Why: so only the hospital group can read the records, and no one else has any access.
Q3: Accounts & Roles
Which accounts exist on the server now, and what is each one allowed to do?
admin-intern: read-only access to service status and logs. staff-intern: hospital group, read-only on records, no admin rights. patient: non-interactive shell, time-bound. contractor: locked and expired.
Q4: Disabling Contractor
How did you disable the contractor's account, and how did you confirm it actually stopped working?
Commands used to disable the account:
sudopasswd-lcontractor# -l: locks password login entirelysudousermod-e1970-01-01\contractor# -e: expires the account, forcing# an immediate lockoutsudogpasswd-dcontractor\svc-backup# -d: drops contractor from the# group, revoking script accesssudorm-f\/etc/sudoers.d/hospital-backup# -f: deletes the sudoers file that# granted root on the scriptsudochage-lcontractor# -l: confirms expiration took# effect, no password reset neededAccount expires: Jan 01, 1970
Confirmed with chage -l (shows expired) and a rejected SSH attempt.
Q5: Access-Control Scheme
What access-control scheme did you design for the records directory: who can read, who can write, who has no access at all?
The hospital group gets read-only access; only staff-intern is a member. The backup group can run the backup/sync scripts; no human accounts belong to it, only the dedicated service account.
Q6: SSH Hardening
How did you harden SSH?
Key steps to harden SSH:
echo'PasswordAuthentication no'|\sudotee\/etc/ssh/sshd_config.d/10-lab.conf# writes a config disabling# password-based SSH loginsudosshd-t# -t: checks syntax first so a bad# config can't lock everyone outsudosystemctl restart ssh
# reloads sshd with the new rulepassword login: Permission denied(publickey)
Q7: Services & Timers
What services and timers are running on the server, and did you find or fix anything running with more privilege than it needed?
Audit and fix commands:
systemctl list-units --type=service\--state=running# lists only services active nowsystemctl list-timers --all# --all: includes timers that# aren't currently scheduledsudochown root:root \/opt/hospital/sync.sh# removes group ownershipsudochmod750/opt/hospital/sync.sh# rwx owner, r-x group, none else
Q8: Finding: What & Where
What is it, and where did you find it: in the downloaded data, or in a configuration choice you made?
The backup script was owned root:group but group-writable (mode 775), and a sudoers file gave the contractor account NOPASSWD sudo to run it as root.
Q9: Finding: Discovery
How did you discover it? What did you check, or what did the AI suggest, that led you to it?
Checks that led to the finding:
sudo-l# -l: lists sudo rights without# running anything(root) NOPASSWD: backup.shls-la/opt/hospital/backup.sh# -l: long form, -a: show hidden,# reveals the script's real perms-rwxrwxr-x root svc-backup
Q10: Finding: The Exploit
How did you exploit it? What commands did you run, in what order?
The exploit pattern (illustrative):
echo'id' >> /opt/hospital/backup.sh# appends the id command to the script's endsudo/opt/hospital/backup.sh# runs it as root: the NOPASSWD sudo rule# found in Q9 needs no passworduid=0(root) gid=0(root)# proves the injected id ran as root,# not as the contractor account
Q11: Finding: Attacker Impact
What could an attacker actually do with this, once exploited?
Any member of that group with this sudo grant could escalate straight to root: read every patient record, modify system files, or erase the evidence of having done so.
Q12: Finding: The Fix
How did you fix it? What command(s) closed it?
Commands that closed it:
sudorm-f\/etc/sudoers.d/hospital-backup# -f: deletes the file granting# contractor root on the scriptsudochown root:root \/opt/hospital/backup.sh# removes svc-backup group ownersudochmod750/opt/hospital/backup.sh# rwx owner, r-x group, none else
Q13: Finding: Confirm the Fix
How did you confirm the fix worked: did you re-test the exploit and see it fail?
The retest, and its result:
sudo-ucontractortest-w\/opt/hospital/backup.sh\&&echo"Still writable"\||echo"Write denied: fix confirmed"# -u: runs the check as contractor,# -w: tests write access directlyWrite denied: fix confirmed
Which commands prove contractor's sudo rights and account are both gone?
(click to reveal)
Verification:
sudo-l-Ucontractor# -U: checks rights for a specific userUser contractor is not allowed torun sudochage-lcontractor# -l: lists the account's expirationAccount expires: Jan 01, 1970
Which commands prove the intern account can no longer log in?
(click to reveal)
Verification:
getentpasswdintern# confirms the shell is now nologinintern:x:1011:1018::/home/intern:/usr/sbin/nologinssh intern@<IP>
# tries logging in with the old keyPermission denied (publickey)
Which commands prove only root can read the backups?
(click to reveal)
Verification:
ls-ld/var/backups/hospital# -d: shows the directory's own permsdrwx------ root rootsudo-ucontractorcat\/var/backups/hospital/*.tar.gz# -u: runs the read attempt as contractorPermission denied
Which commands prove contractor can't run backup.sh as root anymore?
(click to reveal)
Verification:
sudo-ucontractortest-w\/opt/hospital/backup.sh\&&echo"Still writable"\||echo"Write denied"# -u: run as contractor, -w: check writeWrite deniedsudo-l-Ucontractor# -U: confirms the NOPASSWD grant is goneUser contractor is not allowed torun sudo
Which commands prove svc-backup can't edit sync.sh anymore?
(click to reveal)
Verification:
sudo-usvc-backuptest-w\/opt/hospital/sync.sh\&&echo"Still writable"\||echo"Write denied"# -u: run as svc-backup, -w: check writeWrite deniedsystemctlcat hospital-sync.service \|grep User
# confirms the dedicated service accountUser=svc-sync
Student Reflections (Anonymized)
What Went Well
Snapshot isolation made exploit tests reversible, and testing from Kali confirmed the real network path.
Group and file access management went smoothly once the work actually got going.
Dedicated service accounts and ACLs gave clear, repeatable evidence for every retest.
SSH key-based auth felt like the clearest, most effective fix to make.
What They'd Do Differently
Start earlier and pace the work evenly, instead of one late sprint at the end.
Keep a command transcript and take screenshots before and after every change.
Verify a snapshot restore (chage -l, groups, sudo -l) right away, before moving on.
Audit /etc/sudoers.d and group memberships early, not after re-testing finds it.
Physical lab: Ethernet cables through a real switch. Remote: one virtual network, same effect.
The 5 Teams at a Glance
Full role breakdown on the next slides.
Orange = a team actively builds or attacks here. Gray = shared infrastructure.
Top-Down: Attacker's View
Bottom-Up: Defender's View
⚠️ Starting at the wrong end wastes time: an attacker checking cables first, or a defender guessing at the app before confirming the link is up, both burn time on the wrong layer.
Who Can Write?
Monitor Read's account is technically restricted to read-only commands: enforced, not just agreed to.
Network Setup
Decided in advance, not live
Bridged mode on every VM
NAT can't reach other laptops
Shared /etc/hosts file early
Static IPs, pre-assigned: 10.0.0.1x = Laptop 1 (.10 Ubuntu, .11 Kali), 10.0.0.2x = Laptop 2, and so on. The switch and cabling are shared infrastructure: each team just plugs in and configures its own.
# recon first, always
nmap -sV -p- clindata-vm-ip
# only authorized targets on
# this class network, nothing else
Attacker: Deliverable
A live page, not a report
Triggers real commands
Proves the work, not just talk
Role: Clinical Data Admin
Secure the shared Ubuntu seed
RBAC: groups set the rules
Most privileged, real target
# from Kali, configure your own Ubuntu
ssh clindata-vm "sudo groupadd physicians"
ssh clindata-vm "sudo chgrp -R physicians /srv/clinical-data"
ssh clindata-vm "sudo chmod -R 2770 /srv/clinical-data"
Clinical Data: Deliverable
A live page, not a report
Triggers real commands
Proves the work, not just talk
Role: Web Interface
Log-in-as-persona web app
Reads Clinical Data's rules
No write access to records
# deploy and watch the persona-login app
ssh webapp-vm "sudo systemctl restart persona-app"
ssh webapp-vm "journalctl -u persona-app -f"
Web Interface: Deliverable
A live page, not a report
Triggers real commands
Proves the work, not just talk
Phase 1: Component Testing
Not on the shared network yet
Verify your own Ubuntu+Kali
Proves your config is right
Not that anyone can reach you
Each team tests its own pair in isolation. This catches configuration mistakes cheaply, before the switch is ever connected.
Phase 2: Integration Testing
Physical check: links up first
Test 1: reachability
Test 2: functional
Final: dress rehearsal
Test 1 (Week 10, Tue) is pure reachability. Test 2 (Week 12, Tue) is functional: real attacks, backups, monitoring, logs. Final Integration (Week 13, Thu) is a full dress rehearsal before the demo.
Demo: Week 14
Tuesday, Nov 24 only
Thu Nov 26 is Thanksgiving
Monitor Read runs first sweep
Then Dec 4 Project Showcase
Week 14 has only one class day. Monitor Read runs the physical check and the first nmap sweep at the start of every integration test.
Weekly Status Updates
Every team, every week
Weeks 10 through 13 (4 total)
What's done, blocked, next
Keeps problems visible early instead of surfacing for the first time at an integration test.
GitHub Submission
team1: Monitor Read
team2: Monitor Write
team3: Attacker
team4: Clinical Data Admin
team5: Web Interface
Submit to your own team folder: code, your presentation slides (.pptx), and every other artifact. If it's part of your deliverable, it belongs in your folder, not just attached to Canvas.
AI use is allowed: clearly state which parts used AI and which parts you did without it.
Week 1: Kickoff
✅ Teams created (5 teams)
Not on the shared network yet
Just your own VM pair, for now
Phase 1: component testing
One core task this week, the same for every team: clone the shared repo, run setup.sh on your own Ubuntu VM, and confirm the 4 persona accounts and clinical data match the shared baseline. That's Phase 1: proving your own pair works, not yet that anyone else can reach you.
Get the Hospital Use Case
Clone the shared repo
Run setup.sh on your Ubuntu
Check for SETUP OK
Starts world-readable on purpose
sudoaptinstall-ygit# make sure git is availablegitclone\https://github.com/SE4CPS/2026-COMP-175.gitcd 2026-COMP-175/project/part-2/Hospital-VM
chmod +x setup.sh
# makes the script runnable./setup.shSETUP OK
Reuses every module this course taught: virtualization, networking, access control, logging, automation, containers, and IaC, all working together in one real system.
Final Exam Logistics
When & Where
Wed, Dec. 10, 8-10 AM
Location: CTC 214
Covers Modules 1 through 15
How to Prepare
Review each module's commands
Re-run the hardest labs
Check the Schedule page links
Every module's own command-reference table (the "All Commands" slide) is the fastest way to jog your memory on real syntax before the exam.