Automatic security updates (unattended-upgrades, dnf-automatic, livepatch)

Updated November 1, 2026

On Debian/Ubuntu you use unattended-upgrades, on RHEL you use dnf-automatic. Auto-apply only security updates, do everything else by hand. Kernel live patching (livepatch/kpatch) delivers security fixes without a reboot. Skip autoreboot, but keep a notification that a reboot is needed.

Why it matters

Most publicly-known CVEs are exploited within 30 days of disclosure. If updates land once a quarter, the exposure window is huge. But applying everything by hand across a 100-node fleet does not work, you need automation.

The compromise is to install only security updates automatically and apply everything else after QA. This covers 95% of real-world risk and avoids breaking applications with an accidental upgrade of a MySQL major version.

Debian / Ubuntu, unattended-upgrades

The package ships in the base repos. To install it:

apt install unattended-upgrades apt-listchanges
dpkg-reconfigure -plow unattended-upgrades
# → creates /etc/apt/apt.conf.d/20auto-upgrades

The main config is /etc/apt/apt.conf.d/50unattended-upgrades:

Unattended-Upgrade::Allowed-Origins {
    "${distro_id}:${distro_codename}-security";   // security only
    // "${distro_id}:${distro_codename}-updates"; // everything else is off
    // "${distro_id}ESMApps:${distro_codename}-apps-security";
    // "${distro_id}ESM:${distro_codename}-infra-security";
};

Unattended-Upgrade::Package-Blacklist {
    "linux-*";                              // do not upgrade the kernel
    "postgresql-*";                          // handle the DB separately
};

Unattended-Upgrade::Mail "ops@example.com";
Unattended-Upgrade::MailReport "on-change";
Unattended-Upgrade::Remove-Unused-Kernel-Packages "true";
Unattended-Upgrade::Remove-Unused-Dependencies "true";

Unattended-Upgrade::Automatic-Reboot "false";        // do NOT reboot
Unattended-Upgrade::Automatic-Reboot-Time "03:00";   // used if "true"

And /etc/apt/apt.conf.d/20auto-upgrades:

APT::Periodic::Update-Package-Lists "1";              // apt update
APT::Periodic::Unattended-Upgrade "1";                // run it
APT::Periodic::Download-Upgradeable-Packages "1";
APT::Periodic::AutocleanInterval "7";

A systemd timer apt-daily-upgrade.timer runs it once a day with a random delay (to avoid peaks).

systemctl list-timers apt-daily-upgrade.timer
unattended-upgrade --dry-run -d   # debug what would be installed

Logs:

/var/log/unattended-upgrades/unattended-upgrades.log
/var/log/unattended-upgrades/unattended-upgrades-dpkg.log

RHEL / Fedora / CentOS / rocky, dnf-automatic

This is a standard dnf module:

dnf install dnf-automatic

Config, /etc/dnf/automatic.conf:

[commands]
upgrade_type = security              # default | security | minimal
random_sleep = 300                    # 0-N seconds delay (anti-thundering)
network_online_timeout = 60
download_updates = yes
apply_updates = yes                   # actually install (not just download)

[emitters]
emit_via = stdio,email                # where to send notifications
system_name = web-01.prod

[email]
email_from = root@web-01.prod
email_to = ops@example.com
email_host = localhost

[base]
debuglevel = 1

Then enable the timer:

systemctl enable --now dnf-automatic.timer

# or the "download only, no apply" variant
systemctl enable --now dnf-automatic-download.timer
systemctl enable --now dnf-automatic-notifyonly.timer

There are three timer units, so you pick the behavior you want.

SUSE, zypper-automatic / yast2-online-update

zypper install yast2-online-update-configuration
yast online_update_configuration

Or cron:

0 3 * * * /usr/bin/zypper -n patch --category security

Kernel live patching, updating the kernel without a reboot

The most painful CVEs are at the kernel level (privilege escalation). They require a new kernel → reboot → downtime.

Live patching lets you inject a hotfix into the running kernel without rebooting. The technology works like this:

  1. The patch is compiled into a kernel module
  2. The kernel loads the module through the livepatch API
  3. Ftrace redirects calls from the old function to the new one

Providers:

ProviderDistroType
Canonical LivepatchUbuntu (free for up to 5 machines with UA)proprietary
kpatchRHEL/CentOS/Fedoraopen-source + RH patches
kGraftSUSE Enterprise (legacy)merged into Linux
TuxCare KernelCareuniversalcommercial

Canonical livepatch (Ubuntu)

sudo snap install canonical-livepatch
sudo canonical-livepatch enable <token>           # token from ubuntu.com/security
sudo canonical-livepatch status

Free tier, up to 5 machines. It is set up through Ubuntu Pro.

kpatch (RHEL/Rocky/AlmaLinux)

dnf install kpatch
systemctl enable --now kpatch
# patches arrive as kpatch-patch-<kernel-version>.rpm
dnf install kpatch-patch-5.14.0-362.13.1

Or a Red Hat Enterprise Linux for Live Patching subscription.

When live patching does not fit

  • A large change (a new syscall, a new subsystem) is not livepatch-able. Only a reboot helps.
  • Userspace updates (libc, openssl) are not helped by livepatch, you have to restart the processes. Use needrestart (Debian) or dnf needs-restarting.
  • Initramfs / bootloader are never live.

So you still have to plan reboots, just less often: once a quarter or after a large CVE window.

Reboot strategy

In a cluster with redundancy:

  1. Drain the node (k8s kubectl drain, or pull it out of the LB)
  2. Apply the pending kernel update / reboot
  3. Wait for healthy
  4. Uncordon → next node
  5. Roll through all of them.

Tools:

  • kured (Kubernetes Reboot Daemon), a DaemonSet that watches /var/run/reboot-required and performs a rolling reboot
  • system-reboot Ansible playbook
  • AWS Systems Manager Patch Manager, for cloud VMs

It looks simple, but in production with 100+ nodes the coordination is critical: without kured you end up rebooting the whole control plane at once.

Userspace restart, needrestart / needs-restarting

After an update, processes keep using the old .so files:

$ openssl version
OpenSSL 3.0.13                       # new
$ ls -la /proc/$(pgrep nginx)/maps | grep libssl
→ libssl.so.3.0.11 (old, deleted from disk but still loaded)

The fix:

# Debian/Ubuntu
apt install needrestart
needrestart -r i                     # interactive: what to restart?
needrestart -r a                     # auto-restart

# RHEL
dnf install yum-utils
needs-restarting -r                  # is a reboot required?
needs-restarting -s                  # which services?

You can configure unattended-upgrades together with needrestart so that services restart automatically (with a whitelist).

Checking status in production

# How many security updates are pending?
apt list --upgradable 2>/dev/null | grep -i security | wc -l

# On RHEL
dnf updateinfo list security

# When did the last auto-upgrade run?
grep "Run install" /var/log/unattended-upgrades/unattended-upgrades.log | tail

A metric for monitoring (Prometheus node-exporter): apt_upgrades_pending, apt_upgrades_pending_security. Alert if security is >0 for more than 24h.

When things go wrong

  • unattended-upgrades does not run: check /etc/apt/apt.conf.d/20auto-upgrades, it must contain the line APT::Periodic::Unattended-Upgrade "1";. Otherwise run dpkg-reconfigure.
  • Cache has broken packages during an auto-upgrade is a dependency conflict, and it stays pending. Fix: run apt --fix-broken install by hand.
  • dnf-automatic installs everything, not just security: in automatic.conf upgrade_type = default. Change it to security.
  • A service is not restarted after a lib update: needrestart is not configured, or it is on the blacklist. Check /etc/needrestart/conf.d/*.
  • The reboot-required file is created, but nobody reboots: if there is no kured or reboot cron, the nodes pile up updates. Visibility: Prometheus node_reboot_required.
  • Livepatch is applied, but uname -r shows the old kernel: this is normal. Use canonical-livepatch status or cat /proc/sys/kernel/osrelease.
  • An old LTS has no updates but the CVE exists: this is an EOL distro. Migrate to a supported one or pay for extended support (Ubuntu ESM, RHEL EUS).

Commands

  • unattended-upgrade --dry-run -d: Debug mode: shows what would be installed right now, without making real changes
  • systemctl list-timers apt-daily-upgrade.timer: When the auto-update last ran and when it runs next
  • apt list --upgradable 2>/dev/null | grep -i security: Only security updates that are pending, a quick perimeter check
  • dnf updateinfo list security: RHEL/Rocky, all pending security updates with CVE numbers
  • needrestart -r a: Auto-restart every process holding stale .so files after a lib update
  • sudo canonical-livepatch status: Current state of kernel livepatch on Ubuntu, which patches are applied
  • ls /var/run/reboot-required && cat /var/run/reboot-required.pkgs: Whether a reboot is needed and because of which packages, the standard Debian marker

See also