26.1. Establishing a Security Baseline
A baseline is the answer to three questions: what does this system expose, who can administer it, and how does it stay current. The answers become the reference point that every later change - a new service, a new certificate, a suspected compromise - is compared against. This section builds that reference on sec1 and records it where it can be checked later.
26.1.1. Mapping Exposed Services and Administrative Trust
Work over the practice network from the client where possible: it is the view an outsider gets, and it survives even when the server host is in a bad state. john's SSH access to sec1 was established with the host-key verification and key installation procedure of Chapter 20: the client recorded sec1's host key at first connection after checking it against a fingerprint obtained from the server side, and later sessions reuse that known-host entry without a prompt. A routine login looks like this on secclient, as john:
$ ssh john@web.sec1.lab 'id; hostname'
uid=1001(john) gid=1001(john) groups=1001(john)
sec1
The response proves two things at once: the account john exists on sec1
with UID 1001, and the name resolves to the host that answers for
web.sec1.lab. On the server itself the picture that matters is what is
listening. On sec1, as john, from the workspace:
$ sudo ss -tulpn
Netid State Recv-Q Send-Q Local Address:Port Peer Address:PortProcess
udp UNCONN 0 0 0.0.0.0:68 0.0.0.0:* users:(("dhclient",pid=1535,fd=7))
udp UNCONN 0 0 127.0.0.1:323 0.0.0.0:* users:(("chronyd",pid=633,fd=5))
udp UNCONN 0 0 [::1]:323 [::]:* users:(("chronyd",pid=633,fd=6))
tcp LISTEN 0 511 0.0.0.0:80 0.0.0.0:* users:(("nginx",pid=95811,fd=5),("nginx",pid=95810,fd=5),("nginx",pid=93535,fd=5))
tcp LISTEN 0 128 0.0.0.0:22 0.0.0.0:* users:(("sshd",pid=893,fd=6))
tcp LISTEN 0 511 0.0.0.0:8443 0.0.0.0:* users:(("nginx",pid=95811,fd=9),("nginx",pid=95810,fd=9),("nginx",pid=93535,fd=9))
tcp LISTEN 0 20 127.0.0.1:25 0.0.0.0:* users:(("exim4",pid=11752,fd=5))
tcp LISTEN 0 511 0.0.0.0:443 0.0.0.0:* users:(("nginx",pid=95811,fd=7),("nginx",pid=95810,fd=7),("nginx",pid=93535,fd=7))
tcp LISTEN 0 511 [::]:80 [::]:* users:(("nginx",pid=95811,fd=6),("nginx",pid=95810,fd=6),("nginx",pid=93535,fd=6))
tcp LISTEN 0 20 [::1]:25 [::]:* users:(("exim4",pid=11752,fd=6))
tcp LISTEN 0 128 [::]:22 [::]:* users:(("sshd",pid=893,fd=7))
tcp LISTEN 0 511 [::]:443 [::]:* users:(("nginx",pid=95811,fd=8),("nginx",pid=95810,fd=8),("nginx",pid=93535,fd=8))
Each line answers "who accepts connections, on which address, from which
process". The address half of each entry is as important as the port:
0.0.0.0:22 means sshd accepts connections on every interface, while
127.0.0.1:25 and [::1]:25 mean exim4 accepts local mail delivery only -
an exposure to local processes, not to the network. chronyd's port 323 is
loopback-only for the same reason. dhclient's UDP port 68 is the DHCP
client side of the management interface, not a server. nginx answers on 80,
443, and 8443 on the practice host because it carries this chapter's
demonstration site, whose TLS listeners are configured in Section 26.4.6;
on a host that has not deployed the TLS sites yet, only the port-80
listener appears. The reading rule is unchanged: every line must map to a
service you can name and defend. Chapter 18 covers the
socket vocabulary and the nftables filtering that follows from this list.
The second half of the map is what starts at boot, because a listener that returns after every reboot is the real exposure. Still on sec1, as john:
$ sudo systemctl list-unit-files --type=service --state=enabled --no-pager
UNIT FILE STATE PRESET
apparmor.service enabled enabled
audit-rules.service enabled enabled
auditd.service enabled enabled
chrony.service enabled enabled
cron.service enabled enabled
e2scrub_reap.service enabled enabled
exim4.service enabled enabled
getty@.service enabled enabled
grub-common.service enabled enabled
ModemManager.service enabled enabled
networking.service enabled enabled
nginx.service enabled enabled
rsyslog.service enabled enabled
ssh.service enabled enabled
sshd-keygen.service enabled enabled
systemd-pstore.service enabled enabled
udisks2.service enabled enabled
unattended-upgrades.service enabled enabled
wtmpdb-update-boot.service enabled enabled
19 unit files listed.
The list is the boot-time promise: nineteen services, each of which should
be either wanted or removed. Some are structural (networking, ssh,
getty); some are the chapter's own material (nginx, auditd,
audit-rules, apparmor); a few are worth questioning on a server, and
Section 26.1.2 takes those up.
Administrative trust completes the map. On a Debian system the relevant
facts are which accounts exist, which of them can become root through
sudo, and whether root itself can log in remotely. The account inventory
lives in /etc/passwd and the sudo policy in /etc/sudoers and
/etc/sudoers.d/, managed with the tools of
Chapter 5; sshd's own restrictions are
covered in Section 20.4.1. The baseline worth writing down is
short: one administrative account (here john), a sudo policy that names
what it may run, remote root login disabled, and the audit rules of
Section 26.6.2 watching the files that could change any of that.
26.1.2. Reducing Installed Software and Unneeded Listeners
Every installed package is patch surface: when its next vulnerability arrives, it arrives for you too, whether or not you use the software. Measure the surface before trimming it. On sec1, as john, from the workspace:
$ apt-mark showmanual | wc -l
179
$ dpkg-query -f '${binary:Package}\n' -W | wc -l
468
The first pipeline counts packages marked for manual installation - the set
apt autoremove will not take away and the set a person chose, directly or
through a task or dependency chain. The second counts every installed
package, dependencies included: 468 packages on the practice host, 179 of
them deliberate choices. The number to act on is the first: a package
nobody chose is usually a package nobody needs, and the trim procedure is
the apt autoremove and apt-mark workflow of
Chapter 6.
The listener and service lists from Section 26.1.1 name the usual
candidates. On the practice host, exim4 answers only on the loopback
interface - Debian's local-delivery-only default, which keeps cron mail
working without accepting network connections. A host whose services never
send local mail can remove it entirely with sudo apt purge exim4
exim4-base exim4-config followed by autoremove; the listeners in
ss -tulpn are the check that it worked. ModemManager, enabled in the
service list, manages mobile-broadband modems; on a server with no such
hardware it is inert, and removing the modemmanager package reclaims the
boot slot. udisks2 is the desktop disk-automation service; same test. The
discipline is the point: name each enabled unit, keep the ones with a
workload, and remove the rest rather than merely stopping them, so the
state survives reboots and package upgrades.
26.1.3. Security Advisories, Supported Packages, and Update Policy
Debian's security process publishes fixes to the stable-security archive
suite, and an unpatched host slowly becomes the weakest link in whatever
else this chapter protects. Check what is pending, on secclient this time,
as john, from the workspace:
$ apt list --upgradable 2>/dev/null | head -10
Listing...
apt-utils/stable,stable-security 3.0.4 amd64 [upgradable from: 3.0.3]
apt/stable,stable-security 3.0.4 amd64 [upgradable from: 3.0.3]
base-files/stable 13.8+deb13u8 amd64 [upgradable from: 13.8+deb13u5]
bash/stable 5.2.37-2+b10 amd64 [upgradable from: 5.2.37-2+b9]
bind9-dnsutils/stable,stable-security 1:9.20.30-1~deb13u1 amd64 [upgradable from: 1:9.20.21-1~deb13u1]
bind9-host/stable,stable-security 1:9.20.30-1~deb13u1 amd64 [upgradable from: 1:9.20.21-1~deb13u1]
bind9-libs/stable,stable-security 1:9.20.30-1~deb13u1 amd64 [upgradable from: 1:9.20.21-1~deb13u1]
bsdextrautils/stable,stable-security 2.41.5-0+deb13u1 amd64 [upgradable from: 2.41-5]
bsdutils/stable,stable-security 1:2.41.5-0+deb13u1 amd64 [upgradable from: 1:2.41-5]
Selected output; head -10 keeps the first ten entries of a longer list.
The suite column carries the important fact: entries naming
stable-security have fixes published by the Debian security team, and
they belong in the next maintenance window. Before that window, see what
an upgrade would actually change. On sec1, as john:
$ sudo apt-get -s upgrade
Conf libfreetype6 (2.13.3+dfsg-1+deb13u2 Debian:13.8/stable [amd64])
Conf grub-common (2.12-9+deb13u4 Debian:13.8/stable [amd64])
Conf libglib2.0-0t64 (2.84.4-3~deb13u5 Debian:13.8/stable [amd64])
Conf libss2 (1.47.2-3+b12 Debian:13.8/stable [amd64])
Conf libtasn1-6 (4.20.0-2+deb13u1 Debian:13.8/stable [amd64])
Conf openssl (3.5.9-1~deb13u1 Debian:13.8/stable [amd64])
Conf python3-idna (3.10-1+deb13u1 Debian:13.8/stable [all])
Conf python3-urllib3 (2.3.0-3+deb13u2 Debian:13.8/stable, Debian-Security:13/stable-security [all])
Conf qemu-utils (1:10.0.13+ds-0+deb13u1 Debian:13.8/stable [amd64])
Conf rsyslog (8.2504.0-1+deb13u2 Debian:13.8/stable [amd64])
Selected output - the final configuration lines of the simulation; the
package-index preamble and the per-package Inst lines above them are
omitted. The -s flag makes apt-get report the whole upgrade without
touching the system, which answers in advance the questions an upgrade
window will ask: which services restart, whether any package is held back
for new dependencies, and whether the Inst lines name anything that
needs a reboot. The actual upgrade is the routine procedure of
Chapter 6.
For a host's real exposure to known vulnerabilities, the package count
is not enough; you want the advisory list against installed versions. The
debsecan package queries the Debian Security Tracker for exactly that.
Its useful options:
| Option | Description |
|---|---|
--suite trixie |
Name the release whose tracker data should be matched |
--format detail |
One advisory per entry, with the affected package and fixed version |
--only-needed |
Restrict the report to packages actually installed |
On sec1, as john:
$ debsecan --suite trixie --format detail | head -12
CVE-2026-54369
acl before version 2.4.0 contains a symlink traversal vulnerability in ...
installed: acl 2.3.2-2+b1
(built from acl 2.3.2-2)
fixed in unstable: acl 2.4.0-1 (source package)
CVE-2026-54370
acl before version 2.4.0 contains a time-of-check to time-of-use (TOCT ...
installed: acl 2.3.2-2+b1
(built from acl 2.3.2-2)
fixed in unstable: acl 2.4.0-1 (source package)
Selected output; the tracker lists every advisory affecting installed
packages and head -12 keeps the first two. The installed: line gives
the vulnerable version on this host; fixed in unstable: names the
version that contains the fix, which usually reaches stable-security
shortly after. Read the list the way an administrator does: advisories in
packages the host actually exercises first, exposures reachable over the
network ahead of local-only issues, and everything else tracked rather than
treated as an emergency.
An update policy closes the loop. Debian 13 enables
unattended-upgrades.service by default - it appears in the
Section 26.1.1 service list - configured to install security-suite
updates automatically. Keep that default for the security suite, decide
consciously about the general stable updates, and set the
Unattended-Upgrade::Mail and automatic-reboot options with the
configuration walkthrough in
Section 6.4.2. The remaining policy elements
are scheduling - a known window in which the apt-get -s upgrade preview
and the real upgrade both happen - and recording, after each window, that
the reboot-requiring upgrades named in checkrestart-style output or
/var/run/reboot-required were actually rebooted.
26.1.4. Physical Access, Firmware, and Encryption Boundaries
Everything earlier in this section assumed the attacker is on the network.
Physical access is a different threat: a machine whose disks can be
removed, or whose boot process can be altered, hands over whatever is
stored in plaintext. Encryption moves that boundary. The installer's
guided encrypted-LVM option covers whole-disk encryption at install time;
Chapter 13 covers LUKS2 in depth - container
format, keyslots, passphrases, and /etc/crypttab persistence. What
belongs here is the boundary itself, and the smallest honest way to see it
is a disposable encrypted container in the workspace, which needs no spare
disk and no partition layout.
First look at what is currently stored in plaintext on the practice host. On sec1, as john:
$ sudo lsblk -o NAME,FSTYPE,MOUNTPOINTS
NAME FSTYPE MOUNTPOINTS
vda
└─vda1 ext4 /
One virtual disk, one ext4 root filesystem, no encryption anywhere: the practice host, like a default installation, keeps everything readable to anyone who can mount its disk elsewhere. A laptop or a server holding sensitive data would instead use the encrypted layout of Chapter 13, and the boundary check below is the same either way.
Create the practice container - a 64 MiB image file and a passphrase file that stands in for a real passphrase you keep in your head or a sealed envelope. On sec1, as john, from the workspace:
$ truncate -s 64M luks-demo.img
The command prints nothing; it only allocates the file. Give it something to look at:
$ ls -l luks-demo.img
-rw-rw-r-- 1 john john 67108864 Nov 23 16:35 luks-demo.img
Store the passphrase for the exercise, where only john can read it:
$ printf 'LUKS-Demo-Passphrase\n' > luks-passphrase.txt
$ chmod 600 luks-passphrase.txt
Both commands are silent; the redirection writes the file. Attach the image to a loop device, which needs root because loop devices are a system-wide resource:
$ sudo losetup -f --show ~/debian-handbook/security/luks-demo.img
/dev/loop0
-f picks the first free loop device and --show prints its name - the
output that the next commands need. The cryptsetup subcommands and options
used here:
| Option | Description |
|---|---|
luksFormat --type luks2 |
Write a LUKS2 header and keyslot area onto the device |
--key-file FILE |
Read the credential from FILE instead of prompting interactively |
--batch-mode |
Skip the interactive "Are you sure?" confirmation |
luksOpen --key-file FILE NAME |
Unlock and map the container as /dev/mapper/NAME |
status NAME |
Report the active mapping's type, cipher, and backing device |
luksClose NAME |
Remove the mapping |
$ sudo cryptsetup luksFormat --type luks2 --batch-mode --key-file ~/debian-handbook/security/luks-passphrase.txt /dev/loop0
Silent when it succeeds. --batch-mode skips the irreversible-operation
confirmation that Section 13.4.2 shows
interactively; typing it is the one protection --batch-mode costs you,
so use the flag in scripts only where the target device is already known
to be disposable. Open the container:
$ sudo cryptsetup luksOpen --key-file ~/debian-handbook/security/luks-passphrase.txt /dev/loop0 handbook-demo-crypt
Warning: keyslot operation could fail as it requires more than available memory.
The warning is cryptsetup noting that the argon2id key derivation is configured for more memory than this small virtual machine comfortably has; the operation itself succeeded. Put a filesystem and a file inside, and read it back through the mapping:
$ sudo mkfs.ext4 -q /dev/mapper/handbook-demo-crypt
Silent because of -q. Make a mount point, mount, write, and read:
$ sudo install -d /mnt/handbook-demo
$ sudo mount /dev/mapper/handbook-demo-crypt /mnt/handbook-demo
$ sudo sh -c 'printf "encrypted data\n" > /mnt/handbook-demo/proof.txt'
$ cat /mnt/handbook-demo/proof.txt
encrypted data
Only the last command prints; the writes are silent. Now inspect the mapping itself:
$ sudo cryptsetup status handbook-demo-crypt
/dev/mapper/handbook-demo-crypt is active and is in use.
type: LUKS2
cipher: aes-xts-plain64
keysize: 512 bits
key location: keyring
device: /dev/loop0
loop: /home/john/debian-handbook/security/luks-demo.img
sector size: 512
offset: 32768 sectors
size: 98304 sectors
mode: read/write
The loop: line records where the ciphertext really lives: the image file
in the workspace. Close the container and detach the loop device:
$ sudo umount /mnt/handbook-demo
$ sudo cryptsetup luksClose handbook-demo-crypt
$ sudo losetup -d /dev/loop0
All three are silent. The boundary claim can now be stated precisely: from
now on, luks-demo.img on disk is indistinguishable from random bytes -
the data survives, but reading it requires the passphrase and a LUKS
header intact. That is what full-disk encryption buys, and what it does
not: while the system runs and the container is open, the data is
plaintext to the operating system, to every process with permission, and
to a cold-boot attack on the RAM that holds the key. Encryption protects
data at rest; it does nothing for a running host's other exposures, which
is why it is one layer of this chapter, not its subject.
Firmware is the boundary below the disk. On a UEFI host, Secure Boot
verifies the boot loader's signature before the kernel runs, and
mokutil reports and manages that state. On the practice host, as john:
$ sudo mokutil --sb-state
EFI variables are not supported on this system
The practice host boots legacy BIOS, so the command has no EFI variable
store to read and says so; it exits nonzero. On a UEFI machine the same
command prints SecureBoot enabled or SecureBoot disabled, and a
disabled state on a machine that should have it enabled belongs on the
baseline's discrepancy list. Firmware updates are the same story from the
other side: on hardware whose vendor ships signed firmware packages, the
fwupd daemon and fwupdmgr get-updates fetch and stage them; the
practice host has no such firmware channel, so the honest baseline entry
is "firmware updated per vendor procedure", not a command capture. What
matters for the rest of this chapter is the discipline: record the boot
mode, the Secure Boot state, and the firmware update channel as facts you
can compare against, because a boot chain you cannot describe is a boot
chain you cannot audit.