Home UbuntuUnattended Upgrades on Ubuntu 24.04: Full Setup Guide

Unattended Upgrades on Ubuntu 24.04: Full Setup Guide

by Knowledge Base Linux
unattended upgrades automatically patching an Ubuntu 24.04 server

Security patches only protect you once they are installed, and on a busy server the gap between a patch release and a manual update is exactly when attackers strike. Setting up unattended upgrades on Ubuntu 24.04 closes that gap: the system downloads and installs security updates on its own, so known vulnerabilities get fixed within hours instead of weeks. In this guide you will configure unattended upgrades safely, control which updates are applied, schedule automatic reboots, and add email notifications so you always know what changed.

Unattended upgrades are not about blindly updating everything. The default Ubuntu configuration installs security updates only, leaving feature updates and major package changes for your manual review. That balance makes unattended upgrades a safe default for production servers, provided you test the reboot policy and monitor the logs. By the end of this guide, your server will patch itself reliably without surprise restarts.

unattended upgrades schedule for automatic security updates on Ubuntu

How Unattended Upgrades Work on Ubuntu 24.04

Unattended upgrades are driven by the unattended-upgrades package and a systemd timer. Once a day, the timer runs /usr/lib/apt/apt.systemd.daily, which updates the package lists and then installs packages that match the allowed origins in /etc/apt/apt.conf.d/50unattended-upgrades. The main configuration file is /etc/apt/apt.conf.d/20auto-upgrades, which turns the daily download and install steps on or off.

By default, only the security pocket (${distro_id}:${distro_codename}-security) is enabled. Updates from the regular updates pocket are commented out, which is the behaviour you want on a server: security fixes arrive automatically, while everything else waits for a human decision. Logs land in /var/log/unattended-upgrades/, and a summary is mailed to root if mail is configured.

Prerequisites

  • An Ubuntu 24.04 server with sudo access and a working internet connection.
  • SSH access, so you can verify the configuration without relying on the console.
  • Basic familiarity with editing files in nano or your preferred editor.
  • Optional: a mail setup (Postfix or an SMTP relay) if you want email reports.

Step 1: Install and Enable Unattended Upgrades

Install the package and confirm the timers are active:

sudo apt update
sudo apt install -y unattended-upgrades apt-listchanges
sudo systemctl enable --now unattended-upgrades
systemctl list-timers apt-daily apt-daily-upgrade

You should see both apt-daily.timer and apt-daily-upgrade.timer listed as active. The first refreshes package lists; the second performs the actual upgrade. If either timer is missing, reinstalling the package and rebooting once usually restores them.

Step 2: Configure Which Updates Are Installed

Open the main unattended-upgrades configuration file:

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

Confirm the security origin is enabled and leave the updates pocket commented out unless you deliberately want all updates applied automatically:

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

You can also blacklist packages that must never be upgraded automatically, which is essential for pinned kernels or database servers:

Unattended-Upgrade::Package-Blacklist {
    "linux-image-generic";
    "postgresql-16";
};

Blacklisting is safer than holding packages with apt-mark, because it only affects the automatic run; you can still upgrade those packages manually whenever you are ready.

Step 3: Set the Automatic Reboot Policy

Some security updates, notably kernel updates, only take effect after a reboot. By default, unattended upgrades do not reboot the server. For a server that must stay patched, enable automatic reboots inside a quiet window:

Unattended-Upgrade::Automatic-Reboot "true";
Unattended-Upgrade::Automatic-Reboot-Time "03:30";

Pick a time with the lowest traffic for your audience, and make sure your services start on boot with systemd so a reboot is a brief interruption rather than an outage. If your server cannot reboot unattended, leave this off and handle kernel updates during your own maintenance windows instead.

Step 4: Enable Email Notifications for Unattended Upgrades

Silent automation is risky if nobody reads the logs. Configure the report address so every run sends a summary:

Unattended-Upgrade::Mail "[email protected]";
Unattended-Upgrade::MailReport "only-on-error";

Change only-on-error to always for the first two weeks while you build confidence, then switch back to reduce noise. If no mail arrives at all, check that your mail transport works with echo "test" | mail -s "test" [email protected] before blaming unattended upgrades.

Step 5: Test Unattended Upgrades with a Dry Run

Never wait a day to find out whether the configuration works. Run a dry run that reports what would be upgraded without changing anything:

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

Read the output carefully: it lists the packages that match the allowed origins and flags any configuration errors. Follow it with a real verbose run on a test server, or accept the next scheduled run on production and check /var/log/unattended-upgrades/unattended-upgrades.log the next morning.

Troubleshooting Unattended Upgrades

Nothing is installed. Check that 20auto-upgrades contains APT::Periodic::Unattended-Upgrade "1"; and that the timers are active. A common cause is a stale lock from a crashed apt run; clear it with sudo rm /var/lib/apt/lists/lock only after confirming no apt process is running.

Updates download but never install. Look for a package on hold or a dpkg interruption. Run sudo dpkg --configure -a and sudo apt install -f, then re-run the dry run.

The server reboots at the wrong time. The reboot time is in the server local timezone. Verify it with timedatectl and remember that a server set to UTC reboots at a different local hour than you expect.

Email reports never arrive. Test mail delivery independently, check the spam folder, and confirm the Mail line is uncommented. Unattended upgrades cannot report through a mail system that is itself broken.

Conclusion

With unattended upgrades configured, your Ubuntu 24.04 server now installs security patches on its own schedule, reboots only inside a window you chose, and reports every run. That single change removes the most common reason servers stay vulnerable: the human delay between a patch release and a maintenance window. Pair it with regular log reviews and a tested backup, and your patching process becomes boring in the best possible way. For related maintenance, see our guide to configuring logrotate on Ubuntu 24.04 and our UFW firewall setup for Ubuntu 24.04. The official documentation is at Ubuntu Server automatic updates.

You may also like

KbLinux

Typically replies within a day

Hello, Welcome to the site. Please click below button for chatting me through Telegram.