Skip to main content

Automatic Security Updates on Debian and Ubuntu

Debian and Ubuntu can install security updates by themselves with a tool called unattended-upgrades. Ubuntu turns it on by default, while on Debian you turn it on with two commands. A few settings control which updates it installs and whether the system may restart on its own.

What it means

Software can contain security holes, and attackers actively search for computers where those holes are still open. Security updates close known holes. Every day without an update is another day your computer stays open to attack.

Automatic updates work like a smoke detector. You set it up once, and then it watches quietly in the background while you do other things. On a home computer, or on a server that nobody checks every day, this is the easiest way to stay safe. If your computer runs Debian or Ubuntu (two common versions of Linux), make sure it is turned on.

By default, the tool installs only security updates. New versions of programs, with new features, still wait for you. That keeps the risk of an update breaking something low.

There is one limit. Some updates, such as a new kernel (the core of the system), only take effect after a restart. The system lets you know when a restart is needed.

Back to top

How to use it

Install the tool first, if it is missing:

sudo apt install unattended-upgrades

Then switch the automatic updates on:

sudo dpkg-reconfigure -plow unattended-upgrades

Answer Yes. The tool then writes two lines to the file /etc/apt/apt.conf.d/20auto-upgrades:

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

Each 1 means "every day". To see what the tool would do, run a test that installs nothing:

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

Logs go to /var/log/unattended-upgrades/. If the file below exists, a restart is needed:

cat /var/run/reboot-required

On Fedora and other systems with DNF, dnf-automatic does the same job.

Back to top

How it works

Two systemd timers do the work. apt-daily.timer downloads the package lists, and apt-daily-upgrade.timer installs the updates. Each one starts at a random moment inside a time window, so the mirrors do not get a request from every computer at once. To see when they run next:

systemctl list-timers 'apt-daily*'

The file /etc/apt/apt.conf.d/50unattended-upgrades decides which updates get installed. Debian uses the key Unattended-Upgrade::Origins-Pattern there, and Ubuntu uses Unattended-Upgrade::Allowed-Origins. By default, only the security archive of your release is allowed. You can add the normal updates archive as well, but then larger changes arrive without your review.

The same file holds a few more useful settings:

  • Unattended-Upgrade::Automatic-Reboot "true"; restarts the system when an update needs it. Add Unattended-Upgrade::Automatic-Reboot-Time "03:00"; to choose the time.
  • Unattended-Upgrade::Package-Blacklist lists packages that the tool must never update, for example a database server that you update by hand.
  • Unattended-Upgrade::Mail "root"; sends a report by email, if the system can send mail.

Servers often cannot restart whenever they like. A service that uses an updated library keeps running the old version until the service itself restarts. The tool needrestart lists these services and can restart them. Then only kernel updates need a full reboot. For the kernel itself, Ubuntu offers Livepatch, which applies some kernel fixes without a reboot.

Watch out for one pitfall. If a package asks a question during an update, for example about a changed configuration file, unattended-upgrades keeps the old file and moves on. After large updates, read the logs.

Back to top

Sources

Back to top
The welovelinux penguin

The byline of welovelinux news articles. AI helps us write the first draft, and a human editor, Peter Martin, checks every article against its sources before it is published.

Frequently asked questions

On Ubuntu, yes: unattended-upgrades is turned on by default. On Debian, you turn it on yourself with two commands: sudo apt install unattended-upgrades and sudo dpkg-reconfigure -plow unattended-upgrades. Answer Yes when it asks.

No, by default it only installs security updates. New versions of programs, with new features, still wait for you. This keeps the risk that an update breaks something low. You can add the normal updates archive, but then larger changes are installed without your review.

Not by default. Some updates, such as a new kernel, only take effect after a restart. If the file /var/run/reboot-required exists, a restart is needed. For automatic restarts, set Unattended-Upgrade::Automatic-Reboot "true"; and choose a time with Automatic-Reboot-Time.

Run sudo unattended-upgrade --dry-run --debug. It shows which updates the tool would install, without installing them. The log files of the real runs are in /var/log/unattended-upgrades/.