Ubuntu Unattended-Upgrades: Security-Only Patching Without Surprise Reboots
Configure Ubuntu Unattended-Upgrades for security-only patching, verify with dry-run, and avoid unplanned reboots on 22.04 and 24.04 LTS.
06 Sept 2026, 19:49 UTC

The problem: automated patching that either misses updates or restarts your database mid-query
Ubuntu includes Unattended-Upgrades, an APT-based service that can automatically download and install security updates from the -security pocket. On many Ubuntu 22.04 LTS and 24.04 LTS server and cloud images the package is installed and the systemd timer is active, but installer defaults vary — minimal cloud images, some ARM builds, and desktop spins may leave it disabled or configured differently. The operational risk is not just missing updates; it is an automatic reboot triggered by a kernel or libc update that interrupts containers, databases, or active user sessions.
Limit to security origins and keep reboots opt-in
The primary configuration lives in /etc/apt/apt.conf.d/50unattended-upgrades. Before editing, back up the original file:
sudo cp /etc/apt/apt.conf.d/50unattended-upgrades /etc/apt/apt.conf.d/50unattended-upgrades.bak
Open the file with your preferred editor (any root-capable editor works). Find the Unattended-Upgrade::Allowed-Origins block. A security-only configuration uses the exact origin strings that APT reports — no escaped quotes, no variable expansion in the file itself:
Unattended-Upgrade::Allowed-Origins {
"ubuntu:jammy-security";
// "ubuntu:jammy-updates";
// "ubuntu:jammy-backports";
};
On Ubuntu 24.04 LTS replace jammy with noble. The origin format is <distro_id>:<codename>-<pocket>; you can confirm the exact strings on your host with apt-cache policy and looking at the o= and a= fields for the security repository. Commenting out -updates and -backports means only security patches are applied automatically; non-security updates still require deliberate administrator action.
To prevent unplanned restarts, ensure the reboot setting is explicitly disabled:
Unattended-Upgrade::Automatic-Reboot "false";
With this set to false, Ubuntu may still create /run/reboot-required after a kernel update, but the unattended-upgrades service will not reboot the machine on its own.
Worked example: dry-run on a fresh Ubuntu 22.04 LTS server
Assume a clean ubuntu-22.04-server cloud image where the package is installed but the timer status is unknown. Run the following as a user with sudo privileges on the target host:
- Check current timer state:
Expected: a line showingsystemctl list-timers --all | grep unattendedapt-daily-upgrade.timerorunattended-upgrades.timerwithNEXTandLEFTcolumns populated if active. - Preview what would be installed without making changes:
This command is read-only: it refreshes package metadata, evaluates thesudo unattended-upgrade --dry-run --debugAllowed-Originslist, and prints candidate packages. Typical output ends with a summary like:
If another APT process holds the lock, the command exits withPackages that will be upgraded: linux-image-5.15.0-105-generic linux-base 0 upgraded, 0 newly installed, 0 to remove and 2 not upgraded. Dry run complete.E: Could not get lock /var/lib/dpkg/lock-frontend. Wait and retry; do not force the lock. - Verify the service is enabled and the last run completed:
Look forsystemctl status unattended-upgrades journalctl -u unattended-upgrades -n 20 --no-pageractive (exited)on 22.04/24.04 (the service runs via timer, not as a long-running daemon) and log lines ending withAll upgrades installedorNo packages found that can be upgraded unattended. - After the next real run, check whether a reboot is pending:
ls -l /run/reboot-required # if file exists, inspect its content: cat /run/reboot-required # optionally, see which services need restart without a full reboot: needrestart -r l # requires needrestart package
Trade-offs and limitations
- Unattended-Upgrades covers APT packages from the configured Ubuntu pockets only. Third-party PPAs, manually installed
.debfiles, and Snap packages are outside its scope and need separate patching strategies. - A failed or interrupted run can leave the dpkg database locked or packages in
half-configuredstate. Recovery may requiresudo dpkg --configure -a, which changes system state — run only after inspecting the failure in/var/log/unattended-upgrades/unattended-upgrades.log. - Defaults differ between Ubuntu releases and between server, desktop, and cloud images. Verify behavior on the exact target release (check
/etc/os-release) instead of copying a configuration from an older LTS system. - Even with
Automatic-Reboot "false", security updates that require a reboot leave the host in a partially updated state until you restart. The kernel running in memory remains the old version. - Package manager behavior can change between point releases; the origin strings and timer unit names above reflect Ubuntu 22.04 and 24.04 LTS as of 2026-12-04. Confirm on your specific build.
Actionable closing: a pre-flight checklist
- Read
/etc/apt/apt.conf.d/50unattended-upgradeson the target host and confirm only the-securityorigin for your codename is enabled. - Set
Unattended-Upgrade::Automatic-Reboot "false"unless you have a defined maintenance window and workloads that tolerate unplanned restarts. - Run
sudo unattended-upgrade --dry-run --debugand review the package list before enabling on production. - Check
systemctl status unattended-upgradesand the log in/var/log/unattended-upgrades/unattended-upgrades.logafter the first scheduled run. - Monitor
/run/reboot-requiredand plan reboots separately from patching.
Automated security patching reduces the window of exposure, but only when you know exactly what will be installed and when the host will restart. Verify on a staging copy of your production image first.