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_updatessetting 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
| Aspect | unattended-upgrades (Debian, Ubuntu) | dnf-automatic (RHEL and DNF-based) |
|---|---|---|
| Scheduling | systemd apt-daily.timer and apt-daily-upgrade.timer, with random delay | dnf-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 security | Unattended-Upgrade::Origins-Pattern or Allowed-Origins listing the security origin | upgrade_type = security (updates with an issued security advisory) |
| Exclude packages | Unattended-Upgrade::Package-Blacklist (Python regular expressions) | exclude= in the [base] section, which overrides DNF's main configuration |
| Reboot | Automatic-Reboot (default false), Automatic-Reboot-Time, Automatic-Reboot-WithUsers | reboot = never | when-changed | when-needed (default never), reboot_command |
| Reporting | Logs in /var/log/unattended-upgrades/; Mail, MailReport; SyslogEnable (default false) | emit_via (stdio, email, command, command_email, motd); send_error_messages |
| Dry run | unattended-upgrade --dry-run --debug | dnf-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-Securityfor the current codename). Use codename-based matching rather than archive names such asa=stable; the package's own comments warn that archive matching silently follows a different release after a migration. Runapt-cache policyto 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-Blacklistfor packages that need a controlled restart, such as a database server. Anchor names with$: the shipped comments note thatlibc6without 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::MailwithMailReport "on-change"or"only-on-error", and setSyslogEnable "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'sPersistentsetting.
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.
# /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 = securityonly 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-neededreboots only when the update needs it, such as a kernel or systemd update;when-changedreboots after any update. The defaultreboot_commandisshutdown -r +5with a wall message. - Manual equivalents: Red Hat documents
dnf update --securityfor all security updates,dnf update --advisory=RHSA-...for one advisory, anddnf upgrade-minimal --securityfor the smallest version change that fixes the issue. - Kernels: Red Hat notes that
dnfalways 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.
| Layer | Debian and Ubuntu | RHEL and DNF-based | Decision |
|---|---|---|---|
| Detect stale services | needrestart checks which daemons need restarting after library upgrades (-b gives machine-readable output) | dnf needs-restarting -s lists systemd services that can be safely restarted | Always detect; feed results to monitoring |
| Restart services | Ubuntu 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 hook | Automatic for stateless services; scheduled for stateful ones |
| Detect reboot needed | /var/run/reboot-required exists; needrestart -k checks for an obsolete kernel | dnf needs-restarting -r exits 1 if a reboot is required, 0 if not | Report on every host daily |
| Reboot | Automatic-Reboot "true" with Automatic-Reboot-Time "03:00" | reboot = when-needed | Automatic 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, dnfupgrade_type = default) reduces drift but raises the chance of behaviour changes; do it after a pilot ring proves stable.
Rollout plan
- 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.
- Notify-only first: run notify-only (
dnf-automatic-notifyonly.timer) orunattended-upgrade --dry-runon all hosts for a week to see volume and held-back packages. - Pilot ring: enable security-only installation on non-production and a small production sample, with automatic reboot off, for two to four weeks.
- Add restart handling: enable service restarts and reboot detection; agree reboot windows per host group.
- Broad rollout: enable across production in rings, staggering timers so not every host updates at once.
- 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 --upgradablefiltered to security origins ordnf 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
| Framework | Reference | How this guide applies it |
|---|---|---|
| NIST SP 800-53 Rev 5 | SI-2 Flaw Remediation; SI-2(2) Automated Flaw Remediation Status; SI-2(5) Automatic Software and Firmware Updates; CM-3 Configuration Change Control | Automatic installation, status reporting and change control of update scope |
| NIST CSF 2.0 | PR.PS-02; ID.RA-01 | Software maintained according to risk; vulnerabilities identified and recorded |
| CIS Controls v8.1 | 7.3 Perform Automated Operating System Patch Management; 7.4 Perform Automated Application Patch Management | The direct purpose of both tools |
| ISO/IEC 27001:2022 | A.8.8 Management of technical vulnerabilities; A.8.32 Change management | Timely remediation and controlled change |
| MITRE ATT&CK and D3FEND | M1051 Update Software; D3-SU Software Update; reduces exposure to T1190 and T1068 | Closing 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 = securityto 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
/bootfree 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
- Ubuntu Server documentation: Automatic updates
- unattended-upgrades project: README and configuration reference
- Red Hat: Automating software updates in RHEL 9
- Red Hat: Installing security updates
- DNF project: DNF Automatic documentation
- DNF5 project: dnf5 automatic documentation
- DNF plugins core: needs-restarting
- Debian manpages: needrestart(1)
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