Patching and automatic updates

Intermediate · 14 min

Patch servers with unattended-upgrades or dnf-automatic, find services still running old code with needrestart, and plan kernel reboots.

Before thisapt and dpkgdnf and rpmShared libraries and building from sourcesystemd timers

Learn Linux TV · 15 min · from 1:01

Patching and automatic updates

The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.

Taught by Learn Linux TVReport a problem with this video
Not started
Set this lesson's status

What you'll learn

  • Most real compromises use vulnerabilities that already have a fix. The gap between a patch being published and being installed is the risk, so security updates should install automatically.
  • On Debian and Ubuntu, unattended-upgrades runs from `apt-daily-upgrade.timer`. `20auto-upgrades` switches it on, and `50unattended-upgrades` chooses which origins to install from, security only by default.
  • On Fedora and the RHEL family, dnf-automatic does the same from a systemd timer. `apply_updates` defaults to false, so set it, and `upgrade_type = security` limits it to advisories.
  • Installing a fix does not change a running process. Services keep the old library in memory until restarted, and the old kernel runs until reboot. `needrestart` and `dnf needs-restarting` find what is stale.
  • Reboots are part of patching. Plan them with automatic reboot windows, or rolling restarts across a fleet. Kernel live patching shortens the gap for some critical fixes but does not replace reboots.

The fix already exists

When a serious vulnerability is announced, distributions usually ship a fixed package within days. Attackers read the same announcements and start scanning. For most servers the real danger is not the unknown zero-day. It is the well-known bug, fixed weeks ago, on a machine nobody updated.

So the goal of patching is to shrink the window between “fix published” and “fix running”. The second half of that phrase matters, and it is where most patching plans fall short.

Debian and Ubuntu: unattended-upgrades

unattended-upgrades comes preinstalled on Ubuntu Server. On Debian, install the package if it is not already there. Two pieces of apt configuration control it. The upstream README says the switch is a pair of lines, which Debian and Ubuntu keep in /etc/apt/apt.conf.d/20auto-upgrades:

APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "1";

What gets installed is set in /etc/apt/apt.conf.d/50unattended-upgrades. Its Origins-Pattern list ships with only the security archive enabled, so ordinary feature updates wait for you. The same file has a Package-Blacklist for anything that must never update unattended, and reboot options that are commented out by default:

Unattended-Upgrade::Automatic-Reboot "true";
Unattended-Upgrade::Automatic-Reboot-Time "02:00";

The README says that Automatic-Reboot reboots “WITHOUT CONFIRMATION” if /var/run/reboot-required exists after the upgrade. That file is created by packages, such as a new kernel, that need a reboot. The Debian wiki recommends putting local changes in a separate file, such as 52unattended-upgrades-local, so package upgrades do not conflict with them.

It runs from two systemd timers, apt-daily.timer to download and apt-daily-upgrade.timer to install, the kind from systemd timers. To see what it would do: sudo unattended-upgrade --dry-run --debug. Logs go to /var/log/unattended-upgrades/.

Fedora and the RHEL family: dnf-automatic

The equivalent is dnf-automatic, configured in /etc/dnf/automatic.conf. The dnf5 documentation (Fedora 41 and later, dnf5-automatic.timer) lists the settings that matter:

[commands]
upgrade_type = security
apply_updates = yes
reboot = when-needed
  • upgrade_type = security installs only updates with a security advisory. The default installs everything.
  • apply_updates defaults to false, so out of the box the timer only downloads. This catches many people.
  • reboot defaults to never. when-needed reboots only when the update requires it, for example a kernel or systemd update.

On RHEL 9 the tool is dnf 4’s dnf-automatic with dnf-automatic.timer. The option names are similar, but check the man page for the version you have. Enable whichever timer exists with systemctl enable --now.

Installed is not running

Here is the part that automatic updates do not finish for you. When a package replaces /usr/lib/.../libssl.so.3, every process that already loaded the old library keeps using the old copy in memory. The file on disk is new, and the running code is still vulnerable. The shared libraries lesson covers how those mappings work. The kernel is the extreme case: a new kernel package changes nothing until the machine boots it.

Two tools find what is stale:

sudo needrestart                   # Debian/Ubuntu: services using old libraries, and kernel status
sudo dnf needs-restarting -s       # RHEL family: services that need restarting
sudo dnf needs-restarting -r       # RHEL family: does the system need a reboot?

needrestart (3.11.1 is current upstream, November 2026) also detects an obsolete running kernel and outdated CPU microcode. On recent Ubuntu releases it runs after every apt operation and offers to restart affected services.

Rebooting on purpose

A patching plan needs a reboot plan. Options, from simplest to most careful:

  • A reboot window, such as Automatic-Reboot-Time or dnf-automatic’s when-needed, for single servers where a minute of downtime at 02:00 is acceptable.
  • Staggered windows across a fleet, so replicas are never down together.
  • Rolling reboots driven by your orchestration, draining each node before rebooting it, for services that must stay up.

Think of it like a hospital changing its staff rota. Patients still need care, so you replace people a few at a time, not the whole shift at once.

Kernel live patching fills part of the gap. Red Hat’s kpatch and Canonical’s Livepatch, part of Ubuntu Pro, can apply fixes for some kernel vulnerabilities to the running kernel. It covers selected critical fixes only, and the patched kernel still has to be replaced by a reboot eventually. Treat it as a way to buy time until the next window, not as a reason to skip it.

Nothing here was run, since there is no Linux machine here. Settings come from the unattended-upgrades README and default config file in the upstream repository, the Debian wiki, the dnf5-automatic man page and the needrestart project page, all read on 2026-11-28.

About the video

The embed is Learn Linux TV’s “Ubuntu 24.04: How to Automate Updates with Unattended Upgrades”, November 2024, from 1:01 to the end, which skips the opening consulting plug. Its chapters cover installing the package, configuring unattended-upgrades and blocking specific packages from updating. It is Ubuntu-only and does not go into stale processes after an update. The Swedish Sysadmin’s dnf-automatic video, with automatic reboots and a custom timer, and Red Hat’s short kpatch explainer are in deeper. I judged all three from their chapters and descriptions, and English from their English caption tracks.

Where this fits

That closes the security group. The last group is about what to do when a patched, hardened server is simply slow, starting with the number everyone quotes and few read correctly: load average and the USE method.

Check yourself

  1. 01unattended-upgrades installed a fixed OpenSSL last night, and a scanner still flags the web server as vulnerable. How can that be?

    The web server process started before the update and still has the old library mapped in memory. It needs a restart. `needrestart` would list it.

  2. 02You enabled the dnf-automatic timer but updates never install. What is the likely cause?

    `apply_updates` defaults to false, so it only downloads. Set `apply_updates = yes` in `/etc/dnf/automatic.conf`, or the equivalent drop-in.

  3. 03What does `/var/run/reboot-required` mean on Ubuntu, and what reads it?

    A package, usually the kernel, has signalled that a reboot is needed for its update to take effect. unattended-upgrades' `Automatic-Reboot` option reboots when it finds that file.

  4. 04Why not let all 50 servers in a cluster reboot automatically at 02:00?

    They would all go down at once. Stagger them, or reboot through a rolling process that drains each node first, so the service stays up.

Go deeper

Notes

Private to you

Esc
↑↓ navigate↵ open? shortcuts

Keyboard shortcuts

Press Esc to close

Anywhere

⌘K
Search and commands
/
Search
?
This sheet
Esc
Close

Reading a lesson

J
Next lesson
K
Previous lesson
B
Bookmark