How to Enable Automatic Security Updates on Ubuntu and Debian

Security patches arrive often, and the gap between a patch release and an attacker using the fixed flaw is sometimes measured in days. Automatic security updates close that gap on servers you do not log into every day. On Ubuntu and Debian, the tool for this job is unattended-upgrades, and setting it up takes a few minutes plus a reboot policy you have actually thought through.

This guide sets up automatic security updates on Ubuntu and Debian, explains which updates get installed, and shows how to confirm the system really updates itself. It covers security patches only by default, not every package upgrade, which keeps the risk low. The unattended-upgrades Ubuntu path and the debian automatic updates path share the same design: apt security updates install from the security pocket, and the auto update configuration lives in two files under /etc/apt/apt.conf.d/.

How Automatic Security Updates Work

Unattended-upgrades runs on a timer, checks the security repositories, and installs patches without asking. It does not install every available update unless you tell it to. By default it pulls from the security pocket only, so a new feature release or a major version change will not land on your server overnight.

The configuration lives in two files: /etc/apt/apt.conf.d/50unattended-upgrades for what gets installed, and /etc/apt/apt.conf.d/20auto-upgrades for how often the system checks and whether it downloads and installs. Most setups only need small edits to those two files.

Before you start, make sure the package is installed and the package lists are current:

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

On Ubuntu, unattended-upgrades usually ships with the base install. On Debian, install it yourself and check that the timer is active with systemctl status unattended-upgrades. If the service is not running, automatic updates are not happening, whatever the config files say.

Enabling Automatic Security Updates Step by Step

Open 50unattended-upgrades and confirm the security lines for your release are uncommented. On Ubuntu you will see entries for the security pocket; on Debian, the security updates origin. Leave the lines for regular updates commented out unless you deliberately want all updates installed automatically. That restraint is what keeps this setup safe: security patches are narrow and tested for your release, while feature updates can change behavior.

Next, open 20auto-upgrades and set the values that turn the system on:

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

The first line refreshes package lists daily. The second line installs security updates daily. You can also set APT::Periodic::Download-Upgradeable-Packages to download updates in advance, which shortens the install window later.

Then run a dry run to see what would happen without changing anything:

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

Read the output. It lists which origins are allowed and which packages would install. If the dry run shows nothing, check the allowed origins in the config file before you assume the system is fine. A silent misconfiguration is the most common failure mode here.

Reboots, Email Reports, and Blacklists

Some security patches need a reboot to take effect, most often kernel updates. Unattended-upgrades can reboot for you with Unattended-Upgrade::Automatic-Reboot "true"; plus a time window, or it can leave the reboot to you. For a server that must stay up, leave automatic reboot off and watch for the reboot-required flag instead. For a server where uptime matters less than patch speed, schedule the reboot in a quiet window, such as 3 a.m., and make sure your services start on boot.

Email reports are worth setting up. Add your address with Unattended-Upgrade::Mail and install a mail sender if the server has none. A daily report that says nothing installed is still useful: it proves the timer ran. No report at all for a week means something broke, and you want to learn that from an empty inbox, not from an incident.

Blacklists protect packages you never want touched automatically. If you pin a kernel version or hold a database package at a specific release, add it to the package blacklist in the config file. A held package that gets upgraded anyway is how a quiet Tuesday turns into a broken service, so test blacklist behavior on a staging machine or a cheap test VPS first.

Verifying Updates Actually Happen

Setup is not done when the config file is edited. Check the log at /var/log/unattended-upgrades/unattended-upgrades.log after the next timer run. It records what was checked, what installed, and what failed. Also check the dpkg log for the install timestamps. If both logs stay silent for days, the timer is not firing, and the fix is usually a disabled service or a wrong entry in 20auto-upgrades.

Also confirm that services restarted cleanly after updates. A patch that installs but leaves a service down is not a successful update. Your backup routine is the safety net here: a snapshot before major patch windows lets you roll back a bad update quickly. Our guide to automating Linux server backups with restic and cron covers a restore-tested setup for exactly this scenario.

Automatic updates are one layer of server hardening, not the whole job. They pair with a firewall, key-only SSH access, and minimal open services. If you are hardening a new machine from scratch, work through our 15 steps to harden a fresh Ubuntu server, then add UFW and Fail2ban for network-level protection, and use the Ubuntu 24.04 production security checklist to review the finished setup. For day-to-day awareness, the metrics in our Linux server monitoring basics guide will show you when a server stops behaving normally after a patch window.

Ditulis oleh

Firdaus Safari Putra

Founder, PT FirKaizen Digital Solutions

Firdaus Safari Putra adalah founder PT FirKaizen Digital Solutions. Ia membangun dan mengoperasikan infrastruktur server di balik panduan ini, dan menulis berdasarkan apa yang benar-benar ia jalankan, uji, dan ukur — bukan teori.