Join our Newsletter — 33% off our NHI Course
Home› Guides› How to automate Linux security updates with unattended-upgrades…
Guide Vulnerability Management

How to automate Linux security updates with unattended-upgrades and dnf-automatic: configure, reboot and verify

PDF for newsletter subscribers · free to read online

← All guides
By NHI Mgmt Group, under the editorial direction of Lalit Choda Updated 28 November 2026 12 min read
On this page

A Linux server can sit exposed to a published flaw for months even though the fix is already in its distribution's repository, because nobody installed the package, or because it was installed and the vulnerable process kept running until the next reboot. This guide is the hands-on companion to programme-level patch policy: how to configure unattended-upgrades on Debian and Ubuntu and dnf-automatic on Red Hat Enterprise Linux and other DNF-based systems so that security updates install on their own, how to handle service restarts and kernel reboots, and how to prove from logs that it is working. It is for Linux administrators, platform engineers and the security teams who audit them. Patch policy, SLAs and tooling choice are covered in the Patch Management Guide; this page is about the per-host mechanics.

Key takeaways

  • Installing is only half the job. A patched library or kernel on disk does nothing until the processes using it restart or the host reboots, so plan restarts and reboots as part of automation, not as an afterthought.
  • Restrict automation to security sources first. Ubuntu's default unattended-upgrades configuration installs from the release and security pockets only, and dnf-automatic can be limited with upgrade_type = security; widen scope only after you trust the process.
  • Defaults differ by distribution. Ubuntu ships unattended-upgrades installed with security updates enabled; on RHEL you install dnf-automatic and pick a timer, and its apply_updates setting defaults to False.
  • Reboots should be deliberate. Both tools can reboot automatically (Automatic-Reboot, reboot = when-needed), but both default to never; choose a window per host group and stagger it.
  • Silence is not success. Ship the update logs and a "reboot required" signal to central monitoring, and alert on hosts that have not run in days.

How the two tools compare

Aspectunattended-upgrades (Debian, Ubuntu)dnf-automatic (RHEL and DNF-based)
Schedulingsystemd apt-daily.timer and apt-daily-upgrade.timer, with random delaydnf-automatic.timer or a mode-specific timer; systemd timers apply a random delay of up to 1 hour by default
Enable switch/etc/apt/apt.conf.d/20auto-upgrades: APT::Periodic::Update-Package-Lists "1"; and APT::Periodic::Unattended-Upgrade "1";systemctl enable --now the chosen timer
Main config/etc/apt/apt.conf.d/50unattended-upgrades/etc/dnf/automatic.conf (DNF 5 also reads drop-ins in /etc/dnf/automatic.conf.d/)
Limit to securityUnattended-Upgrade::Origins-Pattern or Allowed-Origins listing the security originupgrade_type = security (updates with an issued security advisory)
Exclude packagesUnattended-Upgrade::Package-Blacklist (Python regular expressions)exclude= in the [base] section, which overrides DNF's main configuration
RebootAutomatic-Reboot (default false), Automatic-Reboot-Time, Automatic-Reboot-WithUsersreboot = never | when-changed | when-needed (default never), reboot_command
ReportingLogs in /var/log/unattended-upgrades/; Mail, MailReport; SyslogEnable (default false)emit_via (stdio, email, command, command_email, motd); send_error_messages
Dry rununattended-upgrade --dry-run --debugdnf-automatic-notifyonly.timer or dnf check-update --security

Configuring unattended-upgrades on Debian and Ubuntu

Ubuntu Server documentation states that the package is installed by default and automatic security updates are enabled straight after installation, including Expanded Security Maintenance (ESM) where available, with the -updates, -proposed and -backports pockets commented out. On Debian, install unattended-upgrades and enable it with dpkg-reconfigure -plow unattended-upgrades, which writes the two APT::Periodic lines. Confirm the effective configuration with apt-config dump.

  • Origins: keep the security origin lines (on Debian the shipped file matches label=Debian-Security for the current codename). Use codename-based matching rather than archive names such as a=stable; the package's own comments warn that archive matching silently follows a different release after a migration. Run apt-cache policy to see the origin and label values on your host.
  • Third-party repositories: vendor repositories (databases, monitoring agents, container runtimes) are not upgraded unless you add their origin. Decide per repository; many teams add the vendor's security channel only.
  • Exclusions: use Package-Blacklist for packages that need a controlled restart, such as a database server. Anchor names with $: the shipped comments note that libc6 without it matches every package starting with that string.
  • Kernel clean-up: Remove-Unused-Kernel-Packages "true" stops old kernels filling /boot, a common reason updates start failing.
  • Reporting: set Unattended-Upgrade::Mail with MailReport "on-change" or "only-on-error", and set SyslogEnable "true" so events reach your log pipeline.
  • Timing: change the run time with systemctl edit apt-daily-upgrade.timer. Ubuntu notes that a host which was off at the scheduled time may run at next start-up, which you can change through the timer's Persistent setting.

Test before you trust it: sudo unattended-upgrade --dry-run --debug shows what would install and why packages are held back; the README says to look for "sanity check failed" in /var/log/unattended-upgrades/unattended-upgrades.log. Distribution-specific hardening around this is covered in the Ubuntu Server Security Hardening Guide and Debian Hardening.

Configuring dnf-automatic on RHEL and DNF-based systems

Install with dnf install dnf-automatic, then choose how it behaves. Red Hat's documentation describes four timers: dnf-automatic-notifyonly.timer refreshes metadata and reports available updates, dnf-automatic-download.timer downloads without installing, dnf-automatic-install.timer downloads and installs, and dnf-automatic.timer follows /etc/dnf/automatic.conf. The three mode timers override apply_updates and download_updates, so download_updates = yes has no effect under the notify-only timer. On DNF 5 systems the tool runs as dnf5 automatic with dnf5-automatic.timer, and host overrides belong in /etc/dnf/automatic.conf.d/; check which DNF your hosts run before writing configuration.

A sample [commands] section for security-only installation with a controlled reboot:

1 Sample only. This step can disrupt services or delete data. It is based on the public documentation cited: assess it independently against the current official documentation, test outside production and back up first. Use at your own risk.

Sample 1
# /etc/dnf/automatic.conf (sample)
[commands]
upgrade_type = security
download_updates = yes
apply_updates = yes
reboot = when-needed
reboot_command = "shutdown -r +15 'Rebooting after security updates'"

[emitters]
emit_via = stdio,email
send_error_messages = yes
  • Security scope: upgrade_type = security only selects updates that carry an issued security advisory, so it relies on the repository publishing advisory metadata. Red Hat's repositories do; check third-party and mirror repositories before relying on it.
  • Reboot behaviour: when-needed reboots only when the update needs it, such as a kernel or systemd update; when-changed reboots after any update. The default reboot_command is shutdown -r +5 with a wall message.
  • Manual equivalents: Red Hat documents dnf update --security for all security updates, dnf update --advisory=RHSA-... for one advisory, and dnf upgrade-minimal --security for the smallest version change that fixes the issue.
  • Kernels: Red Hat notes that dnf always installs a new kernel rather than replacing the running one, so a kernel fix is not active until reboot.

Platform-specific settings are in the Red Hat Enterprise Linux Security Hardening Guide and the Amazon Linux 2023 Hardening Guide.

Restarts and reboots: making the fix live

A process keeps the old copy of a library mapped in memory until it restarts, and the running kernel stays the old one until reboot. Plan three layers.

LayerDebian and UbuntuRHEL and DNF-basedDecision
Detect stale servicesneedrestart checks which daemons need restarting after library upgrades (-b gives machine-readable output)dnf needs-restarting -s lists systemd services that can be safely restartedAlways detect; feed results to monitoring
Restart servicesUbuntu states needrestart restarts affected services automatically by default from 24.04 LTS; exclude critical ones with $nrconf{override_rc} in /etc/needrestart/conf.d/Restart listed services through your configuration tool or a post-update hookAutomatic for stateless services; scheduled for stateful ones
Detect reboot needed/var/run/reboot-required exists; needrestart -k checks for an obsolete kerneldnf needs-restarting -r exits 1 if a reboot is required, 0 if notReport on every host daily
RebootAutomatic-Reboot "true" with Automatic-Reboot-Time "03:00"reboot = when-neededAutomatic in staggered windows, or orchestrated for clusters

The shipped unattended-upgrades comment is blunt: with Automatic-Reboot on, the host reboots "WITHOUT CONFIRMATION" when /var/run/reboot-required is found. Where reboots are hard to schedule, kernel live patching can cover many kernel fixes between maintenance windows, but it does not replace reboots for every fix. See the Linux Kernel Live Patching Guide.

Decision guidance

  • Stateless and cattle hosts (web tier behind a load balancer, autoscaled nodes): install security updates and reboot automatically, staggered so no more than a fraction of a pool reboots at once. For immutable images, rebuilding and replacing the image regularly can be cleaner than in-place updates.
  • Stateful single hosts (databases, legacy application servers): automate installation of everything except the core service package, detect reboot need automatically, and reboot in an agreed window.
  • Clusters (Kubernetes nodes, database replicas): disable automatic reboot on the host and let an orchestrator drain and reboot one node at a time.
  • Small estates: the built-in tools plus email reports are often enough; give one named person the job of reading failures.
  • Large estates: push the configuration through Ansible or another configuration tool, collect logs centrally and treat per-host email as a fallback. See the Ansible and AWX Security Guide for protecting that control plane.
  • Security only or everything: start with security only. Adding all updates (Ubuntu -updates, dnf upgrade_type = default) reduces drift but raises the chance of behaviour changes; do it after a pilot ring proves stable.

Rollout plan

  1. Inventory: list hosts by distribution, release, DNF or APT version, role and owner; note end-of-life releases, which no longer receive fixes at all.
  2. Notify-only first: run notify-only (dnf-automatic-notifyonly.timer) or unattended-upgrade --dry-run on all hosts for a week to see volume and held-back packages.
  3. Pilot ring: enable security-only installation on non-production and a small production sample, with automatic reboot off, for two to four weeks.
  4. Add restart handling: enable service restarts and reboot detection; agree reboot windows per host group.
  5. Broad rollout: enable across production in rings, staggering timers so not every host updates at once.
  6. Rollback plan: keep snapshots or image versions for critical hosts, know how to downgrade (apt install package=version, dnf history undo), and remove the package from automation with an exclusion until the vendor fixes a bad update.

Where identity fits

Automation runs as root, and the systems that push configuration to it hold privileged credentials. Keep the update path trustworthy: repository signing keys managed by configuration, no trusted=yes or disabled GPG checks on repositories, internal mirrors reachable only by the hosts that need them, and the service account or SSH key your configuration tool uses scoped and rotated like any other machine credential. See the Securing the patch management tool itself guide.

Detection and measurement

  • Last successful run: per host, from /var/log/unattended-upgrades/, syslog or the dnf-automatic emitter; alert when older than three days.
  • Pending security updates: count per host from apt list --upgradable filtered to security origins or dnf check-update --security; target zero beyond your SLA.
  • Reboot debt: share of hosts where a reboot is required, and how long it has been pending.
  • Stale processes: hosts with services still running old libraries, from needrestart batch output or dnf needs-restarting -s.
  • Failure rate: runs ending in error or held packages, grouped by cause (dependency conflicts, full /boot, locked package manager).
  • Time to install: median days from advisory publication to installation across the estate, with entries from the CISA KEV Catalogue Guide tracked separately.

Framework mapping

FrameworkReferenceHow this guide applies it
NIST SP 800-53 Rev 5SI-2 Flaw Remediation; SI-2(2) Automated Flaw Remediation Status; SI-2(5) Automatic Software and Firmware Updates; CM-3 Configuration Change ControlAutomatic installation, status reporting and change control of update scope
NIST CSF 2.0PR.PS-02; ID.RA-01Software maintained according to risk; vulnerabilities identified and recorded
CIS Controls v8.17.3 Perform Automated Operating System Patch Management; 7.4 Perform Automated Application Patch ManagementThe direct purpose of both tools
ISO/IEC 27001:2022A.8.8 Management of technical vulnerabilities; A.8.32 Change managementTimely remediation and controlled change
MITRE ATT&CK and D3FENDM1051 Update Software; D3-SU Software Update; reduces exposure to T1190 and T1068Closing known flaws attackers exploit for entry and privilege escalation

Common failure patterns

  • Installed but never restarted: the package report shows the fix, but the service and kernel still run vulnerable code because reboots were never scheduled.
  • Full /boot: old kernels accumulate, the next kernel update fails, and every later run stalls on the broken dependency.
  • Third-party repos ignored: the OS is current while the database, agent or runtime from a vendor repository is years behind.
  • Silent failure: email goes to a local root mailbox nobody reads, so a broken run goes unnoticed for months.
  • Everyone reboots at once: identical timers across a pool take the whole service down at 03:00; stagger with random delays and ring schedules.
  • Exclusions that never expire: a package excluded after one bad update stays excluded and quietly misses every later security fix.

Practitioner checklist

  • Confirm unattended-upgrades or dnf-automatic is installed and its timer is enabled on every Linux host.
  • Limit automatic installation to security origins or upgrade_type = security to start.
  • Decide per host group whether reboots are automatic, windowed or orchestrated, and configure it.
  • Enable service restart detection with needrestart or dnf needs-restarting.
  • Turn on syslog or a central emitter and alert on hosts with no successful run in three days.
  • Remove old kernels automatically and monitor /boot free space.
  • Review third-party repositories and add their security channels where appropriate.
  • Give every package exclusion an owner and an expiry date.
  • Test rollback for critical hosts with snapshots and package downgrade steps.

Standards and references

Related NHI Mgmt Group resources: Patch Management Guide · Linux Kernel Live Patching Guide · Fixed Patch SLAs vs Risk-Based Remediation Windows · Linux Distribution Security Advisories Guide

PDF for subscribers

Take this guide with you

Every section, table and checklist in one PDF, with links to the sources and related guides. Subscribe to our weekly NHI & AI Identity Journal and we’ll email you a download link.

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

PDF Downloads for Newsletter Subscribers

Get the guide

Enter your details and we’ll email you a download link.

The full guide is free to read online. The PDF is a thank you for subscribing.

Fill in all fields marked * and tick both boxes to continue.