Ubuntu Automatic Security Updates
Configure unattended-upgrades on Ubuntu — automatic security patches, email notifications, reboot scheduling, needrestart integration, package blacklisting, Livepatch for rebootless kernel updates, and monitoring.
Content
Overview
unattended-upgrades automatically installs security patches on Ubuntu servers. It is the single most effective defense against known vulnerabilities. Most breaches exploit known, patched CVEs — automatic updates close the exposure window from weeks to hours. Every Ubuntu server should have this enabled, no exceptions.
Install and Enable
The dpkg-reconfigure command creates /etc/apt/apt.conf.d/20auto-upgrades with the periodic update settings. On fresh Ubuntu Server installations, this is typically already enabled.
Configure Update Sources
Edit /etc/apt/apt.conf.d/50unattended-upgrades to control which repositories are included:
The ${distro_id} and ${distro_codename} variables expand automatically (e.g., Ubuntu:noble-security on 24.04). Keep -updates commented unless you have tested non-security updates on staging first — they can introduce behavioral changes.
Package Blacklisting
Some packages should never be auto-updated because upgrades can break compatibility or require data migration:
The blacklist uses fnmatch patterns. Blacklisted packages still receive security advisories — you must patch them manually during maintenance windows. The goal is controlled upgrades, not skipped upgrades.
Email Notifications
Use "on-change" for production servers — you get notified when packages are actually updated or when errors occur, without daily noise from "nothing to do" reports.
Automatic Reboot Configuration
Kernel updates, glibc updates, and some system library patches require a reboot to take effect. Without a scheduled reboot, these patches sit dormant and the system remains vulnerable:
For high-availability setups, coordinate reboots with your load balancer. Drain the node before reboot and verify health after. Do not enable automatic reboot on all nodes simultaneously — stagger maintenance windows.
Needrestart: Service-Level Restarts
The needrestart package detects services using outdated libraries and restarts them without a full reboot. This covers the majority of patches that would otherwise require a reboot:
The restart mode options:
- -
'i'— interactive (default, asks before restarting) - -
'a'— automatic (restarts services without asking) - -
'l'— list only (shows what needs restarting)
Set 'a' on servers where you want fully automated patching. On critical production nodes, use 'l' and handle restarts during maintenance windows.
Livepatch: Rebootless Kernel Patching
Ubuntu Livepatch applies critical and high-severity kernel CVE fixes without rebooting. This is essential for servers with strict uptime requirements:
Livepatch patches the running kernel in memory. It covers critical and high CVEs — lower severity patches still require a traditional reboot. Use Livepatch to extend the window between reboots, not to eliminate them entirely.
Full Update Schedule Configuration
The Download-Upgradeable-Packages setting pre-downloads packages during the update check. This means the actual upgrade step only needs to install — reducing the window where a partially-downloaded state could cause issues.
Cleanup and Maintenance
Enabling all three cleanup options prevents /boot from filling up with old kernels — a common cause of failed future upgrades.
Monitoring and Verification
Complete Production Configuration
Here is a battle-tested /etc/apt/apt.conf.d/50unattended-upgrades for production:
Best Practices
- -Enable security updates on every server — no exceptions. This is the single highest-impact security measure.
- -Blacklist databases and container runtimes — test their upgrades manually in staging first.
- -Enable automatic reboot during off-peak hours. Kernel patches without reboot are security theater.
- -Configure needrestart in automatic mode for non-critical services. Most patches take effect via service restart, not reboot.
- -Use Livepatch on servers with strict uptime SLAs to bridge the gap between maintenance windows.
- -Monitor
/var/log/unattended-upgrades/and set up alerts for failed updates. - -Test the same update sources on staging before applying to production.
- -Enable all cleanup options to prevent
/bootfrom filling up with old kernels.
Common Pitfalls
- -Not enabling automatic updates at all — the most common security failure on Ubuntu servers.
- -Auto-updating databases without testing — major version bumps can break schema compatibility.
- -Not scheduling reboots — kernel patches require reboot; without it, the old vulnerable kernel stays loaded.
- -Not monitoring for failures — silent update failures leave vulnerabilities open for weeks.
- -Blacklisting too many packages — defeats the purpose. Only blacklist what genuinely needs manual testing.
- -Forgetting to clean old kernels —
/bootfills up, future updates fail, server becomes unpatched.
FAQ
Discussion
Loading comments...