Automatic security updates on Ubuntu Server

Keeping an Ubuntu Server current is one of the cheapest ways to reduce exposure to known vulnerabilities. Manual updates depend on someone remembering to sign in, run apt and decide when a service can restart. Automatic security updates remove that memory test: Ubuntu can fetch package indexes, install eligible fixes without a logged-in administrator, and record what changed.

This guide covers unattended security patching on a self-managed Ubuntu Server, including origin controls, apt timers, reboot handling and monitoring. It applies to a supported Ubuntu LTS release and focuses on apt-managed software; Snap packages, containers and application dependencies need their own update paths.

Understand the unattended patching model

Ubuntu separates package metadata from package installation. The unattended-upgrades package performs the installation, while apt's periodic jobs refresh package lists and invoke it. This creates a patching chain controlled by systemd timers and configuration under /etc/apt/apt.conf.d/.

Repository origins decide which versions are eligible. Administrators should decide whether a server may receive only fixes from Ubuntu's -security archive or also routine changes from -updates. A third-party repository does not become eligible merely because it is popular; its signing key, maintenance status and package contents still need deliberate review.

Automatic does not mean complete. The tool can update a Python library installed through apt, but it will not rebuild a container image, refresh a Snap by itself, patch source code bundled inside an application, or replace a locally modified configuration file. A kernel update also normally needs a reboot before the new kernel is active. Long-running services may need a restart even when the operating system does not require one.

Prepare the server for safe updates

Before enabling automation, confirm that the host has enough free disk space, working time synchronisation and administrative access with sudo. Review outstanding work with apt list --upgradable, then take a provider snapshot or verified backup of application data and important configuration. For a database server, a file copy is not a substitute for a consistent backup.

Give the host a deliberate timezone with timedatectl. A reboot time is interpreted in the server's local zone, and that choice matters in Australia. Sydney and Melbourne change between AEST and AEDT, while Brisbane remains on AEST; a 03:00 maintenance slot therefore has different UTC offsets across the year and between states. Check timedatectl before scheduling any reboot.

The updater needs outbound access to Ubuntu's package archives, but it does not require a public IP address. Australian organisations can choose locally hosted VPS capacity in Sydney, Melbourne or Brisbane through domestic providers, often with support during Australian business hours. A residential NBN or fibre connection can still download updates, although changing IP addresses and consumer routers affect remote access rather than the patching process itself. If a firewall or proxy blocks apt, configure that route before relying on unattended jobs.

Install and inspect the update timers

On many Ubuntu Server images, unattended-upgrades is already installed. Confirm that, and install it if needed:

sudo apt update
sudo apt install unattended-upgrades

The file /etc/apt/apt.conf.d/20auto-upgrades enables the periodic tasks. A common working set is:

APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Download-Upgradeable-Packages "1";
APT::Periodic::Unattended-Upgrade "1";

The values mean daily rather than hourly. The apt-daily.timer and apt-daily-upgrade.timer units schedule the work and can apply a randomised delay so many servers do not contact the archive simultaneously. Inspect the next run with systemctl list-timers 'apt-daily*'. A machine that was powered off at the scheduled time can catch up after returning, but any required reboot still needs deliberate handling.

Control which packages are eligible

Back up the main policy file before editing it:

sudo cp /etc/apt/apt.conf.d/50unattended-upgrades \
  /etc/apt/apt.conf.d/50unattended-upgrades.bak
sudo nano /etc/apt/apt.conf.d/50unattended-upgrades

A focused security-only policy can use an allowed-origins block like this:

Unattended-Upgrade::Allowed-Origins {
    "${distro_id}:${distro_codename}-security";
    // "${distro_id}:${distro_codename}-updates";
};

Here, ${distro_id} expands to Ubuntu and ${distro_codename} to the release name. Remove or comment any broader entries shipped in the file so the intended scope is clear. Keep official Ubuntu repositories signed by the expected key, and add a third-party origin only when its packages have been reviewed. Avoid catch-all patterns because one unchecked repository can place an arbitrary package into an automatic update path.

Package blacklists are available for exceptional cases:

Unattended-Upgrade::Package-Blacklist {
    "example-package";
};

Use a blacklist sparingly. Blocking a package can leave a known vulnerability open, so record why the exception exists, test the replacement procedure and set a review date. Also inspect the Dpkg::Options block. The usual --force-confdef and --force-confold settings preserve a package's default and existing configuration when a maintainer changes a configuration template, reducing the chance that an unattended run overwrites local policy.

Schedule cleanup and reboots

Timers control when the updater runs; the main policy file controls what happens during that run. To permit a reboot after a kernel or other boot-critical update, configure:

Unattended-Upgrade::Automatic-Reboot "true";
Unattended-Upgrade::Automatic-Reboot-Time "03:00";
Unattended-Upgrade::Automatic-Reboot-WithUsers "false";

Automatic-Reboot-WithUsers "false" prevents a forced restart while people are logged in. The downside is that /var/run/reboot-required can remain present and the new kernel may wait for a later maintenance window. Keep Automatic-Reboot "false" on servers where physical console access is uncertain or a reboot would interrupt a service-level agreement, then track the pending restart elsewhere.

Choose the reboot time around actual service use. Australian offices and small IT teams commonly use overnight or weekend change windows, and a 03:00 slot may suit a Sydney or Melbourne host but not a service used by staff or customers in another state. Document the state in the policy, monitor the run and give on-call staff a way to recognise a legitimate restart. Never rely on an unattended reboot as the only recovery plan for a single server.

Cleanup options reduce old packages after upgrades:

Unattended-Upgrade::Remove-Unused-Kernel-Packages "true";
Unattended-Upgrade::Remove-New-Unused-Dependencies "true";
Unattended-Upgrade::Remove-Unused-Dependencies "true";

Removing unused kernels is useful because each kernel consumes disk space, and retaining a recent fallback kernel helps recovery. Dependency removal needs more care: libraries manually installed for an application may look unused to apt yet be required at run time. Test this option on a representative host or leave broad dependency removal disabled until usage is understood.

Finally, separate an operating-system reboot from an application restart. Updating a library under a running web, database or desktop service does not always make the new code active. Pair unattended patching with a deployment process that reloads affected services, checks logs and can roll back a failed release.

Test the configuration and watch its logs

After editing the policy, perform a simulated run:

sudo unattended-upgrade --dry-run --debug

The dry run shows candidate packages, repository decisions and configuration errors without installing the updates. Read the output rather than treating the absence of an error as proof that every intended package will be applied. Pay particular attention to origins, held packages and conflicts involving services that are currently running.

When the dry run is clean, start the one-shot service and inspect its result:

sudo systemctl start unattended-upgrades.service
sudo systemctl status unattended-upgrades.service

The service may report success after finding nothing eligible, which is a valid outcome. Relevant records are available through journalctl -u unattended-upgrades.service --since today and, when logging is enabled, /var/log/unattended-upgrades/unattended-upgrades.log. To see whether the kernel still requires a restart, check /var/run/reboot-required and its companion /var/run/reboot-required.pkgs.

For unattended hosts, monitoring matters more than for a desktop that receives attention every day. A local mail report can be enabled with Unattended-Upgrade::MailReport "on-change" and Unattended-Upgrade::Mail "root", provided the server has a working mail transfer agent. An external monitoring system should also alert on a failed service, a missing run and a pending reboot. Do not place credentials or sensitive patch contents in unencrypted alert messages; summaries and package names are usually enough to start an investigation.

Maintain coverage beyond apt

Snap packages use a separate refresh timer. Check the schedule with systemctl status snapd.refresh.timer and the pending candidates with snap refresh --list. This mechanism keeps supported snaps current, but it does not update a container image or a Python package installed through pip, npm, Composer, RubyGems or another language-specific tool. Each dependency manager needs a defined update owner, even when the operating system is patched automatically.

Container hosts and virtual machines add another layer. A running container keeps the image version it was built from, even if the host kernel and apt packages are current. Rebuild images from a patched base, scan them for known flaws and redeploy them through the normal release process. The same rule applies to virtual machines created from an old template: patch the template as well as the instances built from it.

For an older LTS release that is still within an extended support arrangement, Ubuntu Pro may provide Extended Security Maintenance for applications, infrastructure or the base system. Run pro status to see whether the client is attached and which services are enabled. ESM coverage depends on the applicable entitlement and licence, and it should be treated as a managed add-on rather than assumed to be part of ordinary unattended updates.

For Australian organisations, patching also supports wider security and privacy duties. Patch management is one of the Australian Signals Directorate's Essential Eight practices, while organisations subject to the Privacy Act 1988 and the Australian Privacy Principles still need access controls, incident response, retention decisions and evidence that personal data is protected. Record the update schedule, exceptions, test results and reboot outcomes in the same change system used for the rest of the server's operations.

At the next scheduled maintenance window, run sudo unattended-upgrade --dry-run --debug and attach its output to the server's change record.