Most compromised servers were not defeated by zero-day exploits. They were running a well-known vulnerability for weeks because nobody applied the patch. Setting up unattended-upgrades on Debian 12 closes that gap: security updates are downloaded and installed automatically, every day, without an administrator lifting a finger — while you stay in control of what is allowed to change and when the machine may reboot. This article covers How to Set Up Unattended-Upgrades on in detail.
This guide explains how to install and configure unattended-upgrades on Debian 12, how to limit it to security updates, how to allow specific additional packages, how to schedule automatic reboots for kernel updates, and how to verify the whole system with a dry run and its log files.
How unattended-upgrades on Debian 12 Works – How to Set Up Unattended-Upgrades on
The unattended-upgrades package is a Python service driven by APT’s periodic update mechanism. Two systemd timers run it: apt-daily.timer refreshes the package lists, and apt-daily-upgrade.timer performs the upgrades. Which packages it may touch is controlled by an “allowed origins” list. By default on Debian, that list includes only the stable release and the security repository — exactly the conservative behaviour you want on a production server.

Step 1: Install unattended-upgrades – How to Set Up Unattended-Upgrades on
sudo apt update
sudo apt install -y unattended-upgrades apt-listchanges
The apt-listchanges package shows changelogs during interactive upgrades and can mail you summaries of what the automatic process changed.
Step 2: Enable unattended-upgrades on Debian 12
The quickest supported way to switch the system on is the interactive reconfiguration:
sudo dpkg-reconfigure -plow unattended-upgrades
Answer “Yes” when asked whether to download and install stable security updates automatically. Behind the scenes this writes /etc/apt/apt.conf.d/20auto-upgrades:
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "1";
You can create or edit the same file by hand on servers you provision with scripts. Confirm the timers are active:
systemctl status apt-daily.timer apt-daily-upgrade.timer
Step 3: Review the Allowed Origins
The main configuration lives in /etc/apt/apt.conf.d/50unattended-upgrades. The default Debian section enables the security origin and the main stable origin for the parts Debian marks as safe. Read this file before changing anything — its comments are excellent. A typical conservative configuration keeps:
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";
};
Some administrators remove the first line so that only security updates are applied automatically and feature updates wait for a human. On tightly controlled production machines, that is a defensible choice.
Step 4: Exclude or Include Specific Packages
To prevent a critical package from ever changing unattended (for example, a database server you upgrade manually), add it to the blacklist:
Unattended-Upgrade::Package-Blacklist {
"mariadb-server";
};
Conversely, if you installed software from a third-party repository — Docker’s official repo is a common example — its origin is not in the default list, so it will never be auto-upgraded until you add a matching pattern. The Debian Wiki’s UnattendedUpgrades page shows the exact origin strings to use, which you can discover for any repository with apt-cache policy.
Step 5: Configure Automatic Reboots
Kernel and libc updates only take full effect after a reboot. unattended-upgrades can reboot the machine itself, at a time you choose — useful for fleets, risky for a single critical server:
Unattended-Upgrade::Automatic-Reboot "true";
Unattended-Upgrade::Automatic-Reboot-Time "04:00";
It will only reboot when an upgrade actually requires it and when no user is logged in (unless you also set Automatic-Reboot-WithUsers). Many administrators leave this off on primary servers and rely on monitoring plus a maintenance window instead.
Step 6: Test with a Dry Run and Read the Logs
Never trust an automation you have not observed. A dry run shows exactly what would happen without changing anything:
sudo unattended-upgrades --dry-run --debug
After a real run, results are logged to /var/log/unattended-upgrades/unattended-upgrades.log, and dpkg’s own log records every package change. Check them after the first scheduled run:
tail -n 50 /var/log/unattended-upgrades/unattended-upgrades.log
Optionally, install a local mail setup or a monitoring check so failures (a held package, a full disk) reach you instead of failing silently. A full root filesystem is the most common reason automatic upgrades quietly stop working — the same disk checks from checking disk usage on Linux apply here.
Troubleshooting
Nothing is being upgraded
Verify the timers are enabled and that APT::Periodic::Unattended-Upgrade is "1". Also confirm the machine actually has pending security updates with apt list --upgradable; an up-to-date system correctly does nothing.
A package is held back forever
If upgrading a package would require installing new dependencies, unattended-upgrades skips it by design. Review held packages monthly with a manual sudo apt upgrade and decide whether to accept the change.
Upgrades run at inconvenient times
The timers support randomization, and you can override apt-daily-upgrade.timer with a systemd drop-in to pin the run to your maintenance window.
Conclusion
Configuring unattended-upgrades on Debian 12 takes ten minutes and removes the most common root cause of server compromises: unapplied security patches. Keep the origins conservative, blacklist anything you upgrade by hand, test with a dry run, and read the log after the first cycle. Automatic patching plus a firewall and key-based SSH — the same trio from our Debian 12 server setup guide — covers the overwhelming majority of real-world attacks against small servers.