Lab 3 of 8 · Packages, updates and patching
Patch your server and automate security updates
Inspect packages, apply updates, check whether a restart is needed, and switch on automatic security updates.
- Time
- 45 minutes
- Cost
- Free.
What you learn
Most break-ins use known holes that already have a fix. Keeping packages patched, automatically where possible, is one of the highest-value jobs a sysadmin does.
- Installing, inspecting and removing packages with apt
- Security updates and your security status
- Automatic security updates with unattended-upgrades
- Knowing when a restart is needed
In the AI era: AI can summarise a list of updates in seconds, but version numbers and security notices are facts you check on the system and in official advisories, not in a chat answer.
Get set up
Commands use Homebrew in the Terminal app. Already have a tool? Skip it.
- A terminalOfficial install page ↗
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"Use the Terminal app. The command installs Homebrew, which the other macOS commands use.
Before you start
Finish lab 1.
Start your server and open your repository: run
multipass start sysadmin-labandmultipass shell sysadmin-labon your computer, thencd linux-admin-labon the server.
Step by step
1 See what is waiting
apt updaterefreshes the list of available versions; it does not install anything.sudo apt update apt list --upgradable 2>/dev/null | head -n 20You should see:A list of packages with newer versions, or nothing if the server is up to date.
2 Check your security status
Ubuntu's
protool summarises which installed packages receive security updates.pro security-statusYou should see:A summary of installed packages and where their security updates come from.
3 Install, inspect and remove a package
apt showdescribes a package;dpkg -Llists every file it installed.sudo apt install -y tree apt show tree 2>/dev/null | head -n 8 dpkg -L tree | head tree -L 1 /etc | head sudo apt remove -y treeYou should see:The version and source of
tree, the files it installed, and a short tree of/etc.4 Apply updates and check for a restart
Kernel and core library updates only take effect after a restart, and Ubuntu leaves a marker file when one is needed.
sudo apt upgrade -y if [ -f /var/run/reboot-required ]; then cat /var/run/reboot-required.pkgs; else echo "No restart needed"; fiYou should see:Updates install, then either
No restart neededor the packages that need one. If needed, runsudo reboot, wait a minute and open a new shell.5 Turn on automatic security updates
unattended-upgrades installs security updates every day. The dry run shows what it would do without changing anything.
sudo apt install -y unattended-upgrades sudo dpkg-reconfigure -f noninteractive unattended-upgrades cat /etc/apt/apt.conf.d/20auto-upgrades sudo unattended-upgrade --dry-run --debug 2>&1 | tail -n 5You should see:20auto-upgradescontainsAPT::Periodic::Unattended-Upgrade "1";.6 Ask AI to explain the update history, then check it
Print the recent update history and ask your AI assistant to summarise what changed. Then check one package it mentions with
apt-cache policy(replaceopensslwith a package from your log): the installed version on the server is the fact.tail -n 30 /var/log/apt/history.log apt-cache policy opensslYou should see:Installed:andCandidate:lines; after updating they usually match.7 Write your notes
Create the file with
nano notes/03-patching.md.# Patching my server ## What I updated - Date: ... - Number of packages: ... - Restart needed? Why: ... ## Automatic updates - What unattended-upgrades does: ... - How I check it is working: ... ## AI check - What the AI summary said, and what `apt-cache policy` showed: ...8 Commit and push
Save your work to GitHub from the server.
git add notes git commit -m "Add patching notes" git push
You are done when
Your server has no pending updates, or you know which ones are waiting and why.
Automatic security updates are switched on.
notes/03-patching.mdrecords what you updated and whether a restart was needed.
We check your public GitHub repository and give you a page to share with recruiters, and can add the project to your resume.