A security fix only protects a server once it is installed. This guide is for small businesses and IT staff who run a handful of Ubuntu servers and want security patches installed automatically, with sensible limits, visible logs and a controlled reboot. It refers to Ubuntu 24.04 LTS (noble).
What unattended-upgrades does
The unattended-upgrades package installs updates from the APT repositories you allow, without a person running apt upgrade. On Ubuntu Server it is normally installed and enabled by default and installs security updates only. Two systemd timers, apt-daily.timer and apt-daily-upgrade.timer, trigger the work through /usr/lib/apt/apt.systemd.daily.
Two files control it:
/etc/apt/apt.conf.d/20auto-upgrades– switches the feature on and sets the frequency in days./etc/apt/apt.conf.d/50unattended-upgrades– decides which origins are allowed, which packages are excluded, mail reports and reboot behaviour.
Step 1: Check the current state
Before changing anything, look at what is already active.
sudo apt install unattended-upgrades
systemctl list-timers apt-daily.timer apt-daily-upgrade.timer
apt-config dump | grep -E 'APT::Periodic|Unattended-Upgrade'
The first command only installs the package if it is missing. The timers should show a next run time. In 20auto-upgrades the values APT::Periodic::Update-Package-Lists "1"; and APT::Periodic::Unattended-Upgrade "1"; mean daily; 0 disables the feature.
Step 2: Keep the packaged files, add your own overrides
APT reads all files in /etc/apt/apt.conf.d/ in alphabetical order, so a later file can override or extend an earlier one. Instead of editing 50unattended-upgrades (which a package upgrade may want to replace), put your changes into a separate file. The file name below is our own choice.
sudo nano /etc/apt/apt.conf.d/52local-unattended-upgrades
Which updates are allowed
By default, the Ubuntu configuration allows the release pocket (${distro_codename}), the -security pocket and the Ubuntu Pro (ESM) security origins if they exist on your system. The -updates pocket (regular bug fixes) is commented out. For many servers, security-only is the safest default. If you want the bug-fix pocket as well, add it:
Unattended-Upgrade::Allowed-Origins {
"${distro_id}:${distro_codename}-updates";
};
Entries from the later file are added to the list from the packaged file. Leave -proposed and -backports disabled on production systems.
Excluding packages
Packages that you must upgrade by hand, for example because a vendor application is tied to a specific version, can go on the blacklist. Entries are regular expressions matched from the start of the package name; use $ to mark the end, otherwise libc6 would also match libc6-dev.
Unattended-Upgrade::Package-Blacklist {
"linux-";
"libc6$";
};
Note: the example above is only a syntax illustration. Blocking kernel or libc updates means those security fixes are not installed automatically, so use the blacklist sparingly and document every entry.
Mail reports
Unattended-Upgrade::Mail "admin@example.com";
Unattended-Upgrade::MailReport "on-change";
Replace admin@example.com with your own address. MailReport accepts always, only-on-error and on-change (the default). Mail only works if the server has a working mail transfer agent; test it before relying on it.
Cleaning up
Unattended-Upgrade::Remove-Unused-Kernel-Packages "true";
Unattended-Upgrade::Remove-Unused-Dependencies "false";
Removing old kernels keeps /boot from filling up. Automatic removal of unused dependencies is off by default; enable it only if you accept that APT may remove packages without asking.
Step 3: Decide how reboots are handled
Kernel and library updates only take effect after a restart. If an update requires one, Ubuntu creates /run/reboot-required. By default unattended-upgrades does not reboot (Automatic-Reboot "false"). You have two sensible options.
Option A: Reboot manually in a maintenance window
Check for the flag file as part of your weekly routine:
test -f /run/reboot-required && cat /run/reboot-required.pkgs
Option B: Automatic reboot at a fixed time
Unattended-Upgrade::Automatic-Reboot "true";
Unattended-Upgrade::Automatic-Reboot-Time "03:30";
Unattended-Upgrade::Automatic-Reboot-WithUsers "false";
Automatic-Reboot-Time takes hh:mm, +m (minutes) or now. With Automatic-Reboot-WithUsers set to false, unattended-upgrades does not reboot if users are logged in when the reboot is scheduled; users who log in later do not block it. Use Option B only for machines where a short outage at that time is acceptable and all services start cleanly after boot. Test that once manually.
Service restarts with needrestart
Since Ubuntu 24.04 LTS, needrestart restarts affected services automatically by default after package upgrades. For a service that must never restart on its own, add an override in a file under /etc/needrestart/conf.d/. needrestart only reads files there whose name ends in .conf, for example /etc/needrestart/conf.d/local.conf:
$nrconf{override_rc}{qr(^<critical-service>\.service$)} = 0;
This adds one entry to the existing list. Do not assign a complete new $nrconf{override_rc} = { ... }; hash in a drop-in file: that replaces the packaged defaults, which keep services such as dbus, getty and systemd-logind from being restarted automatically.
Alternatively, $nrconf{restart} = 'l'; only lists services that need a restart instead of restarting them. On 24.04 this setting is respected from needrestart 3.6-7ubuntu4.1 (noble-updates) onwards; check the installed version with apt policy needrestart.
Step 4: Test without changing anything
sudo unattended-upgrade -v --dry-run
This simulates a run and prints which packages would be upgraded from which origins. Check that only the origins you expect appear. Afterwards confirm that the effective configuration is what you intended:
apt-config dump | grep Unattended-Upgrade
Step 5: Verify that it really runs
Automation you never look at is a risk. The logs live in /var/log/unattended-upgrades/:
unattended-upgrades.log– what was checked, installed or skipped.unattended-upgrades-dpkg.log– the output of dpkg during the upgrade.
sudo tail -n 50 /var/log/unattended-upgrades/unattended-upgrades.log
systemctl list-timers apt-daily-upgrade.timer
Once a month, also check that the reboot flag is not set for weeks and that apt list --upgradable only shows packages you expect to be held back.
Limits you should know
- It patches packages from APT. Containers, Python virtual environments, WordPress plugins and manually installed software are not covered.
- Automatic updates are not a backup. Keep a tested restore path (see our earlier article on encrypted restic backups) and snapshot virtual machines before major changes.
- Ubuntu 24.04 LTS receives standard security maintenance until May 2029; Ubuntu Pro (ESM) extends it to May 2034. Plan the upgrade to the next LTS in time.
- Third-party repositories and PPAs only participate if you add their origin to
Allowed-Origins. Do that only for sources you trust.
Checklist
- Timers
apt-daily.timerandapt-daily-upgrade.timerare active. 20auto-upgradesenables daily list updates and upgrades.- Your changes are in a separate file under
/etc/apt/apt.conf.d/. - Allowed origins: security (plus
-updatesonly if you decided so). - Every blacklist entry is documented and reviewed.
- Reboot strategy decided and tested;
/run/reboot-requiredis monitored. - Mail reports tested, or logs reviewed regularly.
unattended-upgrade -v --dry-runshows the expected result.
Our take
For most small servers, automatic security updates with a defined reboot window are clearly safer than manual patching that happens "when there is time". The important part is not the tool but the routine around it: a visible log, a decided reboot policy and a backup you have restored at least once.
Sources
- Ubuntu Server documentation: Automatic updates
- unattended-upgrades: default 50unattended-upgrades.Ubuntu
- Manpage: unattended-upgrade(8)
- Manpage: apt.conf(5)
- Ubuntu Discourse: needrestart changes in Ubuntu 24.04
- Launchpad bug 2068543: needrestart restart mode on 24.04
- needrestart: default needrestart.conf
- Ubuntu release cycle