Unattended upgrades on Ubuntu and Debian: prove they’re working

Set up unattended-upgrades on Ubuntu 24.04 and Debian 13, then check that it really patches: held-back packages, pending reboots, Docker’s repository, and a small check that flags a stuck server within two days. Includes the RHEL equivalent.

Ubuntu Server installs security updates by itself every day through the unattended-upgrades package, and most Debian installs have the same package. The usual problem isn’t that it’s switched off. It’s switched on, the timer fires every morning, and something still doesn’t get patched: a package held back by a config-file prompt, a kernel waiting for a reboot that never happens, Docker from a repository it never looks at, or a run that has been failing quietly for weeks. Ubuntu Server docs: automatic updates ↗

This guide covers the setup on Ubuntu 24.04 and Debian 13 briefly, then the part that matters: checking that it works, the gaps it leaves by design, and a short script you can hook to any monitoring so a stuck server shows up within two days. The RHEL equivalent is at the end.

Check that it’s installed and switched on

dpkg-query -W unattended-upgrades
apt-config dump | grep -E "APT::Periodic::(Update-Package-Lists|Unattended-Upgrade) "
systemctl list-timers apt-daily.timer apt-daily-upgrade.timer

Both APT::Periodic values should be "1". The number is the interval in days, and "0" turns the step off. Both timers should show a next run. The upgrade timer fires at 06:00 with up to an hour of random delay, and it catches up at boot if the server was off at that time. apt-daily-upgrade.timer ↗

If the package is missing or the values are "0", install it and answer yes:

sudo apt install unattended-upgrades
sudo dpkg-reconfigure -plow unattended-upgrades

That writes /etc/apt/apt.conf.d/20auto-upgrades with both values set to "1". Debian’s wiki says most installs include the package with conservative settings, but some don’t include it at all, so check rather than assume. Minimal images and hosting templates are where it most often goes missing. Debian wiki: PeriodicUpdates ↗

Know what it will install

By default, only your distribution’s own updates. On Ubuntu that means the release, its -security pocket and, on machines attached to Ubuntu Pro, the ESM security pockets. Ordinary bug-fix updates from -updates are commented out. Debian’s default takes the release itself (which includes point-release updates) and Debian-Security. Nothing from a repository you added yourself, such as Docker, PostgreSQL or a PPA, is installed until you add its origin. Debian default config ↗

A dry run shows the allowed origins and exactly what the next run would do, without installing anything:

sudo unattended-upgrade --dry-run --debug
apt-cache policy docker-ce     # which origin a package comes from (o= and a= fields)

Read the “Allowed origins are:” line near the top. A package whose origin isn’t in that list stays at its installed version, however old it gets.

Put your changes in a separate file

Don’t edit 50unattended-upgrades. It belongs to the package, and the upstream README warns that local edits there can conflict with the next version and block unattended-upgrades from updating itself. Use a file that sorts later, such as 52unattended-upgrades-local. For single values, the last file read wins. unattended-upgrades README ↗

// /etc/apt/apt.conf.d/52unattended-upgrades-local
Unattended-Upgrade::Automatic-Reboot "true";
Unattended-Upgrade::Automatic-Reboot-Time "04:00";
Unattended-Upgrade::SyslogEnable "true";
apt-config dump | grep -E "Automatic-Reboot|SyslogEnable"

The second command shows what apt actually sees. If a value isn’t what you wrote, another file later in the order sets it again.

Automatic-Reboot acts only when /var/run/reboot-required exists after a run, and it reboots without asking. With no time set it reboots straight away. With "04:00" it schedules the reboot for the next 04:00, which is the following night when the upgrade ran at 06:00. Logged-in users don’t stop it unless you set Automatic-Reboot-WithUsers to "false". SyslogEnable copies each run’s events to syslog, which ends up in the journal and in whatever you already forward logs to.

Whether to reboot automatically depends on the server. For a stateless web node, or anything that can be down for a minute at night, it’s fine. A database host is usually better rebooted by hand in a window. Either way, decide on purpose: with the default, kernel fixes wait until someone happens to reboot.

The gaps it leaves by design

  • Kernels. The new kernel is installed, but the old one keeps running until a reboot. On Debian and Ubuntu, unattended-upgrades ships a kernel hook (/etc/kernel/postinst.d/unattended-upgrades) that creates /var/run/reboot-required and adds the package to /var/run/reboot-required.pkgs.
  • Running services. A patched library only protects processes started after the update. Ubuntu 24.04 runs needrestart after each upgrade and restarts affected services automatically by default, apart from a list of exceptions such as the display manager. On Debian, check how needrestart is configured on your servers. On either, sudo needrestart -r l lists what is still running old code.
  • Packages with a config-file prompt. If an update would ask whether to keep your edited copy of a config file, unattended-upgrades holds the package back and logs “has conffile prompt and needs to be upgraded manually”. It stays held until you upgrade it by hand. Keeping local settings in drop-in directories (sshd_config.d, conf.d) instead of editing the shipped files avoids most of these.
  • Held packages. Anything marked with apt-mark hold is skipped; apt-mark showhold lists them.
  • Other repositories: Docker, databases, PPAs, vendor agents. See the next section.
  • Container images. The base images inside your containers aren’t packages on the host. They get fixes only when you pull new images and recreate the containers.

Sources for the first three: the kernel hook in the upstream repository, Ubuntu’s notes on service restarts, and the conffile check in unattended-upgrade itself. kernel hook ↗ Ubuntu: service restarts ↗ unattended-upgrade source ↗

Docker and other vendor repositories

Docker’s apt repository identifies itself with the origin “Docker” and a suite equal to your release codename (noble, trixie), as its Release file shows. To let unattended-upgrades install Docker updates, add an Origins-Pattern entry to your local file. Entries are added to the shipped list rather than replacing it. Docker’s Release file for noble ↗

// /etc/apt/apt.conf.d/52unattended-upgrades-local
Unattended-Upgrade::Origins-Pattern {
    "origin=Docker,archive=${distro_codename},component=stable";
};

Think before you add it. Upgrading docker-ce restarts the Docker daemon, and by default the daemon shuts down running containers when it stops. Live restore ("live-restore": true in /etc/docker/daemon.json) keeps containers running while the daemon restarts, but Docker supports that only across patch releases, not major upgrades, and it doesn’t apply to Swarm services. Docker docs: live restore ↗

For most small teams the better default is to leave Docker out and upgrade it on a schedule, after reading the release notes:

sudo apt-get update
sudo apt-get install --only-upgrade docker-ce docker-ce-cli containerd.io
docker ps -a --format "{{.Names}}\t{{.Status}}"

The same goes for any repository you leave out: it needs a reminder that doesn’t depend on someone’s memory, because the check below only covers your distribution’s security updates.

Read what it actually did

sudo tail -n 30 /var/log/unattended-upgrades/unattended-upgrades.log
sudo grep -E "conffile prompt|kept back|ERROR" /var/log/unattended-upgrades/unattended-upgrades.log
journalctl -u apt-daily-upgrade.service --since "3 days ago"

Each run logs the allowed origins, the packages it upgraded and anything it kept back. The full dpkg output is in unattended-upgrades-dpkg.log in the same directory. Mail reports (Unattended-Upgrade::Mail and MailReport) need a working mail setup on the server, which most cloud servers don’t have, so don’t count on them.

If you run AIDE, every upgrade changes files it watches. Accept those changes right after the run, not days later. AIDE guide: accepting planned changes →

A check you can alert on

Logs only help when someone reads them. To find a stuck server without logging in, check three things: did the daily run finish successfully recently, are security updates still waiting, and is a reboot pending.

The first has a reliable marker. The script the apt-daily-upgrade timer runs (/usr/lib/apt/apt.systemd.daily) touches /var/lib/apt/periodic/upgrade-stamp only when unattended-upgrade exits successfully, and a run with nothing to install counts as success. If that file is more than two days old, runs are failing or not happening. apt.systemd.daily ↗

#!/bin/sh
# /usr/local/bin/check-patching: prints the problem and exits 1 if patching looks stuck
problems=0

if [ -z "$(find /var/lib/apt/periodic/upgrade-stamp -mtime -2 2>/dev/null)" ]; then
  echo "unattended-upgrade has not finished successfully in 2 days"; problems=1
fi

pending=$(apt-get -s dist-upgrade 2>/dev/null | grep "^Inst" | grep -ci security)
if [ "$pending" -gt 0 ]; then
  echo "$pending security updates waiting"; problems=1
fi

if [ -f /var/run/reboot-required ]; then
  echo "reboot pending for: $(xargs < /var/run/reboot-required.pkgs 2>/dev/null)"; problems=1
fi

exit $problems

It doesn’t need root: apt-get -s only simulates, using the package lists the apt-daily timer keeps fresh. Run it from your monitoring agent, a cron job that posts to chat, or a scheduled job that connects over SSH. Expect it to report waiting security updates for up to a day after a new advisory, until the next daily run. Alert when a server fails two checks in a row, or run the check an hour or two after the 06:00 window.

Test it once by making it fail: sudo touch -d "3 days ago" /var/lib/apt/periodic/upgrade-stamp, run the check, and confirm the alert reaches you. The next successful run puts the stamp back.

RHEL and its rebuilds

The equivalent on RHEL 9 is dnf-automatic. Install it, choose security updates and turn on applying them in /etc/dnf/automatic.conf, then enable the timer: Red Hat: automating software updates ↗

sudo dnf install dnf-automatic

# /etc/dnf/automatic.conf
[commands]
upgrade_type = security
apply_updates = yes

sudo systemctl enable --now dnf-automatic.timer

Use dnf-automatic.timer when you want automatic.conf to decide. The other timers it ships (dnf-automatic-install.timer and the rest) override apply_updates. upgrade_type = security picks only updates that come with a security advisory. dnf-automatic docs ↗

systemctl list-timers "dnf-automatic*"
dnf updateinfo list --security     # advisories still waiting
dnf needs-restarting -r            # exits 1 when a reboot is needed (dnf-plugins-core)

What to show when someone asks

When a customer’s security questionnaire asks how your servers get patched, “unattended-upgrades is on” is a weak answer. “Security updates install daily, these logs show every run, and this check flags any server that misses two days or has a reboot pending” is a strong one. Keep the unattended-upgrades logs with your other logs, because logrotate removes old ones from the server.

One server is a script. Twenty servers, checked every day, is a job. Vigilhold, our host agent for Linux servers, watches process, network, file and SSH signals on every server in one console. Its Business plan adds CVE scanning and package scoring, plus compliance reports that give your auditor evidence for SOC 2. They are not a certification. Linux VPS security checklist → See Vigilhold →

The short version

StepCheck it worked
Installed and onBoth APT::Periodic values are "1" and both apt-daily timers show a next run
Right originsThe dry run’s “Allowed origins” line lists what you expect
Local settings applyapt-config dump shows the values from your 52 file
Reboots decidedAutomatic-Reboot with a time, or a reboot window someone owns
Nothing stuckNo “conffile prompt” lines in the log; apt-mark showhold lists only what you meant to hold
Vendor repos coveredDocker and the rest are in Origins-Pattern or on a schedule
Alertingcheck-patching runs on every server, and you’ve seen it fail once