Home How ToHow to Enable Automatic Security Updates on Ubuntu

How to Enable Automatic Security Updates on Ubuntu

by Knowledge Base Linux
How to Enable Automatic Security Updates — How to Enable Automatic Security Updates on Ubuntu

Most compromised servers were not hacked through zero-days — they were running old packages with known vulnerabilities. Enabling automatic security updates on Ubuntu with the unattended-upgrades package closes that gap: security patches are downloaded and installed every day without you lifting a finger. In this guide you will install and configure unattended-upgrades, control which updates are applied, and decide whether the server may reboot itself.

Why Enable Automatic Security Updates on Ubuntu?

Ubuntu publishes security fixes for the kernel, OpenSSL, sudo, web servers and thousands of other packages through a dedicated security repository. The window between a CVE becoming public and scanners mass-exploiting it is now measured in hours. Manual monthly patching leaves that window wide open. With automatic security updates on Ubuntu:

  • Critical patches are applied daily, including library fixes that need no reboot
  • Thanks to Livepatch or scheduled reboots, even kernel fixes get deployed
  • You still control the scope: security-only by default, no surprise feature upgrades

Automatic updates complement, not replace, access hardening such as configuring the UFW firewall and intrusion blocking.

Step 1: Install unattended-upgrades

sudo apt update
sudo apt install -y unattended-upgrades apt-listchanges

Many Ubuntu server images already include unattended-upgrades; the install command simply ensures it is present and current.

Step 2: Enable Automatic Security Updates on Ubuntu

Run the configuration utility and answer yes:

sudo dpkg-reconfigure --priority=low unattended-upgrades

This creates /etc/apt/apt.conf.d/20auto-upgrades:

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

These two lines tell APT to refresh package lists daily and to run unattended-upgrades — the mechanism behind automatic security updates on Ubuntu.

Automatic security updates Ubuntu schedule with unattended-upgrades

Step 3: Choose Which Updates Are Applied

The behavior is controlled by /etc/apt/apt.conf.d/50unattended-upgrade. By default only the security origin is enabled:

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

Useful options in the same file:

// Remove unused kernels and dependencies automatically
Unattended-Upgrade::Remove-Unused-Kernel-Packages "true";
Unattended-Upgrade::Remove-Unused-Dependencies "true";

// Email a report after each run (requires a working local mail setup)
Unattended-Upgrade::Mail "root";
Unattended-Upgrade::MailReport "on-change";

// Avoid upgrading packages you pin to specific versions
Unattended-Upgrade::Package-Blacklist {
    // "nginx";
};

Blacklist packages whose restarts you must supervise — for example a database server on a busy production box. Everything else keeps patching itself. If your firewall stack is CSF rather than UFW, see our guide to install CSF on Ubuntu for the firewall side of the picture.

Step 4: Decide About Automatic Reboots

Kernel and libc updates only take full effect after a reboot. unattended-upgrades can do this for you — at a time you choose:

Unattended-Upgrade::Automatic-Reboot "true";
Unattended-Upgrade::Automatic-Reboot-Time "04:00";

On a single standalone server, a 04:00 reboot window is usually the right trade-off. On clusters, enable reboots on one node at a time or leave this off and reboot manually during maintenance. The Ubuntu community documentation describes all supported options.

Step 5: Test with a Dry Run

Verify your configuration before trusting it:

sudo unattended-upgrades --dry-run --debug

Then review past runs at any time:

sudo tail -n 50 /var/log/unattended-upgrades/unattended-upgrades.log
cat /var/log/apt/history.log

Troubleshooting

Nothing is being upgraded: confirm 20auto-upgrades contains “1” values and that the apt-daily-upgrade.timer systemd timer is active: systemctl list-timers apt-daily*.

A package was upgraded and the service broke: check /var/log/apt/history.log for exactly what changed, and add the package to the blacklist while you investigate. Rollback on Ubuntu means reinstalling the previous version from the archive if it is still available.

Servers drift out of sync: use the same 50unattended-upgrade file everywhere — drop it into your configuration management so every machine applies the same policy.

Step 6: Check What Is Pending and Consider Livepatch

Automatic updates handle the routine work, but you should still know how to see what is waiting. Security teams and auditors love this visibility, and it takes only seconds to check before a maintenance window. List pending upgrades at any time with:

apt list --upgradable 2>/dev/null
/usr/lib/update-notifier/apt-check --human-readable

The second command prints a summary such as “3 packages can be updated, 2 of them security updates” — a good metric to display in your monitoring or login banner. For servers that cannot tolerate reboots at all, Canonical’s Livepatch service applies critical kernel fixes to the running kernel without restarting; it is free for a small number of machines with an Ubuntu Pro subscription. Livepatch does not replace regular updates — user-space packages still need unattended-upgrades and an occasional reboot — but it shrinks the list of reasons a kernel patch ever has to wait. Whichever route you choose, test the full cycle once: wait for a real security update, confirm it appears in the unattended-upgrades log the next morning, and confirm the machine still behaves. After that, the system quietly takes care of itself.

Conclusion

Turning on automatic security updates on Ubuntu takes five minutes and permanently removes the most common cause of server compromises: unpatched software. Keep the scope to security updates, allow off-peak reboots, review the logs weekly, and patching stops being a chore you postpone and becomes background hygiene that just happens.

You may also like

KbLinux

Typically replies within a day

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