Operating System Debian

How to Set Up Unattended Upgrades on Debian 13 (Trixie)

Install and tune unattended-upgrades on Debian 13 so security updates are applied automatically, with email reports, optional reboots and a schedule you control.

A server that is reachable from the internet should receive security fixes without waiting for you to log in. Debian's unattended-upgrades package downloads and installs updates on a daily schedule. This guide sets it up on Debian 13 (trixie); the steps are the same on Debian 12 (bookworm). Debian 9 and older releases are end-of-life and no longer receive security updates, so a machine still running one of them needs a release upgrade, not automatic updates.

Requirements

  • Debian 13 or Debian 12 with a user that can run sudo.
  • Standard Debian package sources, including the security archive, in your APT configuration.
  • Optional: a working mail setup on the server if you want email reports.

Install the packages

apt-listchanges is optional but useful: it collects the changelog entries of the packages being upgraded.

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

Turn on the daily run

The periodic APT job has to be switched on. Run the package's configuration dialog and answer Yes:

sudo dpkg-reconfigure -plow unattended-upgrades

This writes /etc/apt/apt.conf.d/20auto-upgrades. Check that it contains these two lines (or create the file with them if you prefer not to use the dialog):

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

Confirm what APT actually sees with:

apt-config dump | grep -E 'APT::Periodic|Unattended-Upgrade'

Choose what gets upgraded

The package ships its defaults in /etc/apt/apt.conf.d/50unattended-upgrades. The important block is Unattended-Upgrade::Origins-Pattern, which lists the archives that packages may be upgraded from. On Debian the default allows the installed release and its security archive:

Unattended-Upgrade::Origins-Pattern {
        "origin=Debian,codename=${distro_codename},label=Debian";
        "origin=Debian,codename=${distro_codename},label=Debian-Security";
        "origin=Debian,codename=${distro_codename}-security,label=Debian-Security";
};

${distro_codename} is replaced with the installed release name (trixie or bookworm). Matching by codename means the system keeps following the release you installed and is never moved to the next Debian release automatically. Older tutorials used patterns such as o=Debian,a=stable; avoid those, because "stable" silently starts matching a different release when a new Debian version comes out.

To see which origin, label and codename values your package sources have, run:

apt-cache policy

Keep your changes in a separate file

If you edit 50unattended-upgrades directly, a later package update will ask what to do with your modified copy. Put your own settings in a file that sorts after it instead:

sudo nano /etc/apt/apt.conf.d/52unattended-upgrades-local

A reasonable starting point for a server:

// Send a report to this address (needs a working mail setup)
Unattended-Upgrade::Mail "admin@example.com";
Unattended-Upgrade::MailReport "on-change";

// Packages that must never be upgraded automatically (Python regular expressions)
Unattended-Upgrade::Package-Blacklist {
//      "mariadb-server";
};

// Remove dependencies that are no longer needed after an upgrade
Unattended-Upgrade::Remove-Unused-Dependencies "true";

// Reboot when an update requires it, at a quiet hour
Unattended-Upgrade::Automatic-Reboot "false";
Unattended-Upgrade::Automatic-Reboot-Time "04:00";

Single values in this file override the defaults. Lists behave differently: to replace a list such as Origins-Pattern instead of adding to it, clear it first. This example restricts automatic upgrades to security updates only:

#clear Unattended-Upgrade::Origins-Pattern;
Unattended-Upgrade::Origins-Pattern {
        "origin=Debian,codename=${distro_codename},label=Debian-Security";
        "origin=Debian,codename=${distro_codename}-security,label=Debian-Security";
};

The options that matter

OptionDefaultWhat it does
Unattended-Upgrade::MailemptyAddress for reports. Empty means no mail.
Unattended-Upgrade::MailReporton-changealways, only-on-error or on-change.
Unattended-Upgrade::Package-BlacklistemptyPackages to skip.
Unattended-Upgrade::Remove-Unused-Kernel-PackagestrueRemoves old kernels that are no longer needed.
Unattended-Upgrade::Remove-Unused-DependenciesfalseEquivalent of apt-get autoremove after the run.
Unattended-Upgrade::Automatic-RebootfalseReboots without confirmation when /var/run/reboot-required exists.
Unattended-Upgrade::Automatic-Reboot-TimenowTime of day for that reboot, for example 04:00.

Email reports need a package that provides mailx and a mail transport agent that can deliver from this server. Without them, leave Mail empty and read the logs instead.

Test the configuration

A dry run shows which packages would be upgraded and reveals configuration errors without changing anything:

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

Look for the list of allowed origins near the top of the output and for the packages that would be upgraded. To apply pending updates immediately instead of waiting for the schedule, run the same command without --dry-run:

sudo unattended-upgrade --debug

Check the schedule and the logs

On Debian the work is started by two systemd timers: apt-daily.timer refreshes the package lists and downloads, and apt-daily-upgrade.timer installs the upgrades. See when they last ran and when they will run next:

systemctl list-timers 'apt-daily*'

To move the installation to a fixed time, create an override for the upgrade timer:

sudo systemctl edit apt-daily-upgrade.timer

Enter the following and save. The empty OnCalendar= line clears the packaged schedule before the new one is set:

[Timer]
OnCalendar=
OnCalendar=*-*-* 03:30
RandomizedDelaySec=30m

Every run is recorded in two files: the decisions made by the tool, and the raw output of dpkg:

sudo tail -n 50 /var/log/unattended-upgrades/unattended-upgrades.log
sudo less /var/log/unattended-upgrades/unattended-upgrades-dpkg.log

After kernel or core library updates, check whether a reboot is waiting:

ls /var/run/reboot-required

Turn it off again

Run sudo dpkg-reconfigure -plow unattended-upgrades and answer No, or set APT::Periodic::Unattended-Upgrade "0"; in /etc/apt/apt.conf.d/20auto-upgrades. The full option reference is in the project's README and in the comments of 50unattended-upgrades.

Frequently asked questions

Will unattended-upgrades move my server to the next Debian release?

No, as long as the origin patterns match by codename, which is the default. The system stays on trixie (or bookworm) and only receives updates published for that release. A release upgrade is always a manual job.

Should I enable automatic reboots?

Kernel and some library updates only take full effect after a reboot. On a single server that can tolerate a minute of downtime at night, Automatic-Reboot "true" with a fixed Automatic-Reboot-Time keeps it fully patched. On database servers or cluster members, leave it off and reboot during a planned window.

Why was a package "kept back"?

The tool could not upgrade it safely within its rules, for example because the upgrade needs a package from an origin that is not allowed. Run sudo unattended-upgrade --dry-run --debug to see the reason, then upgrade by hand with sudo apt full-upgrade if the change is acceptable.

Are packages from third-party repositories upgraded too?

Not by default. Only origins listed in Origins-Pattern are considered. To include another repository, look up its origin and codename with apt-cache policy and add a matching line to your local file.

Share story:

Continue reading other guides on How VPS.