Running apt upgrade doesn’t mean a server is safe. The new kernel may not be running yet. A long-lived daemon may still have the old copy of OpenSSL mapped into memory. And the CVE in your security scanner may not have a fix published at all. This guide answers one practical question, “is this Linux server actually patched?”, with commands you can run on Ubuntu and Debian. It covers pending updates, the running kernel versus the installed one, services still using outdated libraries, Livepatch, and checking a specific CVE.
Quick fix:
apt list --upgradable(pending updates),ls /var/run/reboot-required(reboot needed),sudo needrestart -b(kernel and service status in one parseable block), and on Ubuntupro fix CVE-XXXX-YYYY --dry-run(is this CVE fixed here?).
The commands follow the Ubuntu Pro Client, needrestart, and Debian security-tracker interfaces. I ran the distribution-neutral parts on a Debian 13.8 host with needrestart 3.11; the Livepatch and pro steps apply to Ubuntu only. Field names stay stable between releases, so compare fields rather than every line.
What does “patched” actually mean?
A server is only patched when four things are true:
| Layer | Question | Tool |
|---|---|---|
| Packages | Are security updates installed? | apt, unattended-upgrades |
| Kernel | Is the running kernel the newest installed one (or livepatched)? | uname -r, needrestart, Livepatch |
| Processes | Have services restarted onto the new libraries? | needrestart |
| Specific CVE | Is the fixed package version present, or is no fix published yet? | pro fix, Debian security tracker, debsecan |
Most “we patched it” incidents fail at layer 2 or 3.
Step 1: Are security updates pending?
sudo apt update
apt list --upgradable 2>/dev/null | grep -i security
A well-maintained host returns nothing. Any line listing a -security pocket means a fix is available but not installed.
To see what automatic updates would do without changing anything:
sudo unattended-upgrade --dry-run --debug 2>&1 | tail -20
Look for “Packages that will be upgraded”. If unattended-upgrades isn’t installed or enabled, that alone explains drift. Check /etc/apt/apt.conf.d/20auto-upgrades for APT::Periodic::Unattended-Upgrade "1";.
On Ubuntu, the Pro Client gives a summary of installed packages by support status:
pro security-status
pro security-status --format json # for scripts
Step 2: Is the running kernel the patched one?
uname -r
ls /boot/vmlinuz-* | sort -V | tail -1
cat /var/run/reboot-required.pkgs 2>/dev/null
If uname -r is older than the newest vmlinuz file, the fix is on disk but not running. Ubuntu and Debian packages create /var/run/reboot-required (and a .pkgs list) when an update needs a reboot. On Ubuntu, the file existing is your cue.
Use needrestart’s batch mode
needrestart -b prints machine-readable lines, which makes it ideal for monitoring:
sudo needrestart -b
On an Ubuntu host with a newer kernel installed but not yet booted, the batch output looks like this:
NEEDRESTART-VER: 3.6
NEEDRESTART-KCUR: 6.8.0-45-generic
NEEDRESTART-KEXP: 6.8.0-49-generic
NEEDRESTART-KSTA: 3
NEEDRESTART-SVC: ssh.service
NEEDRESTART-SVC: cron.service
How to read the kernel status, per the needrestart documentation:
| KSTA | Meaning |
|---|---|
| 0 | Unknown or failed to detect |
| 1 | No pending kernel upgrade |
| 2 | ABI-compatible upgrade pending |
| 3 | Version upgrade pending (reboot needed) |
KCUR is the running kernel and KEXP is the expected one. The UCSTA, UCCUR and UCEXP lines report CPU microcode the same way (0 means unknown). SVC lists services, CONT containers and SESS user sessions that still run outdated binaries or libraries.
Step 3: Are services still using old libraries?
This is the step people skip. After an OpenSSL or glibc update, every process that had the old library loaded keeps using it until it restarts. On Ubuntu, needrestart runs interactively after apt upgrade and offers to restart services. In batch mode, the SVC lines tell you which ones:
sudo needrestart -r l # list only, restart nothing
sudo needrestart -r a # restart services automatically
The flags shown are the commonly documented list (l) and automatic (a) restart modes. Confirm them with needrestart --help on your version. Services that needrestart won’t restart automatically (like your SSH daemon, on some configurations, or the display manager) still need a planned restart.
Warning: Restarting
ssh.servicenormally keeps existing sessions alive, but always keep a second session open on remote hosts before restarting anything network-related.
Step 4: Is Livepatch covering the kernel?
Canonical Livepatch applies some kernel security fixes without a reboot, on Ubuntu LTS with Ubuntu Pro (free for limited personal use).
sudo pro enable livepatch
canonical-livepatch status --verbose
The status shows the running kernel, whether it’s supported, and the patch state, typically “applied” when fixes are loaded. Livepatch doesn’t replace reboots. It covers selected high and critical kernel CVEs, and kernels eventually fall out of the support window. Schedule reboots anyway; Livepatch buys you time.
Step 5: Is a specific CVE fixed on this host?
On Ubuntu: pro fix
pro fix CVE-2024-6387 --dry-run
pro fix USN-6859-1
--dry-run shows what it would do without installing anything. The Pro Client docs define exit codes that are useful in scripts:
| Exit code | Meaning |
|---|---|
| 0 | Fixed, or the system isn’t affected |
| 1 | The fix can’t be applied (e.g. no fix released, or needs Pro) |
| 2 | Fix applied but a reboot is required |
The example CVE is the 2024 OpenSSH “regreSSHion” issue, chosen because it’s well documented.
On Debian: the security tracker and debsecan
The Debian Security Tracker (security-tracker.debian.org/tracker/CVE-…) shows, per release, which source package version fixes a CVE, or whether it’s marked “no-dsa” or unfixed. Compare it with what’s installed:
apt-cache policy openssh-server
debsecan automates the comparison against tracker data:
sudo apt install debsecan
debsecan --suite "$(. /etc/os-release; echo $VERSION_CODENAME)" --only-fixed
--only-fixed lists vulnerabilities that already have a fix available, which is the actionable list. Check man debsecan for your version’s exact options.
What about RHEL, Fedora and other distributions?
The questions are the same on every distribution. Only the tools change:
| Question | Ubuntu / Debian | RHEL / Fedora family |
|---|---|---|
| Pending security updates | apt list --upgradable |
dnf updateinfo list --security |
| Reboot needed | /var/run/reboot-required, needrestart |
dnf needs-restarting -r |
| Services on old libraries | needrestart |
dnf needs-restarting -s |
| CVE lookup | pro fix, Debian tracker, debsecan |
dnf updateinfo info --cve CVE-… |
| Live kernel patching | Canonical Livepatch | kpatch (RHEL) |
The needs-restarting command comes from the dnf plugins package. On dnf5-based Fedora releases its options may differ, so check dnf needs-restarting --help on your version. On any distribution, the fallback test for whether a process still uses a deleted (replaced) library is the same:
sudo grep -l '(deleted)' /proc/*/maps 2>/dev/null | cut -d/ -f3 | sort -u
After a full restart the list should be empty, but filter it first, as described in the next section. Each PID it prints is a process still holding a replaced file, often a library that an update overwrote. Map the PIDs to services with ps -o pid,cmd -p <pid>. This is roughly what needrestart automates, plus its service mapping and kernel checks.
What these checks found on a real Debian 13 host
I ran Steps 1 and 3 and the deleted-library check on a Debian 13.8 machine that had been up for a while and had just installed a few packages. Three results were worth recording.
| Check | Real result | What it meant |
|---|---|---|
apt list --upgradable | grep -i security | login.defs/stable-security 1:4.17.4-2+deb13u1 and passwd/stable-security | Two security fixes were available but not installed |
sudo needrestart -b | NEEDRESTART-VER: 3.11, NEEDRESTART-KCUR: 6.12.113+, NEEDRESTART-KSTA: 0 | KSTA 0 is “unknown”: the host ran a custom kernel that is not a Debian package, so needrestart had nothing to compare it to |
grep -l '(deleted)' /proc/*/maps | 10+ PIDs, including pulseaudio | Mostly false positives, explained below |
/var/run/reboot-required | Absent | That file is an Ubuntu convention; Debian does not create it by default |
What I ran into
The first surprise was needrestart: command not found. Debian installs it in /usr/sbin, which is not on a normal user’s PATH, so run it with sudo. The second was KSTA: 0. A missing NEEDRESTART-KEXP line together with KSTA: 0 means needrestart could not judge the kernel at all, not that the kernel is current. Treat 0 as “check manually”, for example by comparing uname -r with the newest installed linux-image package.
The third was the (deleted) check. Counting the matching map lines showed 644 /SYSV shared-memory segments, 446 memfd:shared-memory-region entries, and memfd:pulseaudio. None of those are replaced files. Only 70 lines pointed at a real library, libzstd.so.1.5, which an update had replaced. Restricting the pattern to shared objects cut the noise to the processes that matter:
sudo grep -lE '\.so[^ ]* \(deleted\)' /proc/[0-9]*/maps 2>/dev/null | cut -d/ -f3 | sort -u
On that host it listed 14 processes, all still mapping the old libzstd. Those are the services to restart.
How do you turn this into a routine check?
A small script that exits non-zero when anything needs attention fits most monitoring systems:
#!/usr/bin/env bash
set -u
rc=0
[ -f /var/run/reboot-required ] && { echo "reboot required"; rc=1; }
ksta=$(sudo needrestart -b | awk -F': ' '/KSTA/{print $2}')
[ "${ksta:-0}" -ge 2 ] && { echo "kernel upgrade pending (KSTA=$ksta)"; rc=1; }
svc=$(sudo needrestart -b | grep -c 'NEEDRESTART-SVC')
[ "$svc" -gt 0 ] && { echo "$svc services need restart"; rc=1; }
exit $rc
On a fully patched, rebooted host it prints nothing and exits with status 0.
FAQ
My scanner flags a CVE but apt has no update. Am I patched?
Possibly not. Distributions often backport fixes without changing the upstream version number, so scanners that compare upstream versions report false positives. The opposite also happens: no fix has been released yet. Check the distro tracker (Ubuntu CVE pages or the Debian tracker) for your release.
Does a container need its own patching?
Yes. Containers carry their own userland libraries. Rebuild images on patched base images. The host kernel, however, is shared, so kernel fixes come from the host.
How often should I reboot?
Whenever KSTA reaches 3 or /var/run/reboot-required appears, within your maintenance policy. Livepatch can stretch that window for critical kernel CVEs.


Leave a Reply