Most break-ins don’t use exotic zero-days. They use known vulnerabilities on systems nobody patched. unattended-upgrades closes that gap: it installs updates from the Debian archives you choose, automatically and on a schedule. Combined with needrestart, which restarts services still running old library code, and a deliberate reboot policy for new kernels, a Debian server patches itself and tells you about it.
This guide sets up Debian 13 so that it:
- Installs security updates and point-release fixes daily, in a time window you choose
- Restarts affected services automatically, except the ones you exclude
- Reboots for new kernels in a maintenance window (or tells you that it needs to)
- Mails you a report when something changed or went wrong
- Excludes packages that need a coordinated, manual upgrade, without ever excluding the kernel
- Keeps Debian’s own config files untouched, so package upgrades never ask about conffiles
Tested on: Debian 13 “trixie” with the Debian packages
unattended-upgrades,needrestartandapt-listchanges. All commands run as root (or withsudo).
Table of contents
- Placeholders
- How the pieces fit together
- Install the packages
- Enable the daily runs
- Your settings, in a drop-in file
- Third-party repositories
- Excluding packages
- Choose the time window
- needrestart: restart services automatically
- apt-listchanges: mail important news
- Testing
- Monitoring
- Troubleshooting
- Checklist
1. Placeholders
| Placeholder | Meaning |
|---|---|
ops@example.org | Where reports go |
04:00 | Reboot time in the maintenance window. Stagger it across servers. |
03:00 | Start of the daily upgrade window |
2. How the pieces fit together
| Component | What it does |
|---|---|
apt-daily.timer | Runs apt update and pre-downloads upgradeable packages (daily, at a random time) |
apt-daily-upgrade.timer | Runs unattended-upgrade, around 06:00 by default |
/etc/apt/apt.conf.d/20auto-upgrades | Switches those periodic jobs on or off |
/etc/apt/apt.conf.d/50unattended-upgrades | Debian’s default policy. Leave it alone. |
/etc/apt/apt.conf.d/52unattended-upgrades-local | Your policy: origins, mail, exclusions, reboots |
needrestart | Runs as an APT hook after every upgrade and restarts services that still use replaced libraries |
/run/reboot-required | Created when an update (usually a kernel or libc) needs a reboot |
Is it installed by default? Only with a desktop task such as GNOME. Minimal and server installs (netinst without a desktop, cloud images) usually don’t have it, so check.
3. Install the packages
apt update
apt install unattended-upgrades needrestart apt-listchanges
Reports go out by mail, so the host needs a working MTA that provides /usr/sbin/sendmail. Any of these work: Postfix as a satellite relaying to your mail server, or a lightweight relay such as dma or msmtp-mta. Check that delivery works before relying on it:
apt install bsd-mailx # provides the 'mail' command used for the test
echo "Mail test from $(hostname -f)" | mail -s "Mail test from $(hostname -f)" ops@example.orgCode language: PHP (php)
4. Enable the daily runs
Create /etc/apt/apt.conf.d/20auto-upgrades. dpkg-reconfigure -plow unattended-upgrades writes the same file, but the content below is explicit and documented:
// /etc/apt/apt.conf.d/20auto-upgrades
// Values are intervals in days; "0" disables the job.
// Refresh package lists every day
APT::Periodic::Update-Package-Lists "1";
// Pre-download upgradeable packages, so the upgrade window is short
APT::Periodic::Download-Upgradeable-Packages "1";
// Run unattended-upgrade every day
APT::Periodic::Unattended-Upgrade "1";
// Clear obsolete .deb files from the APT cache weekly
APT::Periodic::AutocleanInterval "7";Code language: PHP (php)
APT configuration files use
//and/* โฆ */for comments. Avoid#comments: APT reads lines starting with#includeand#clearas directives.
5. Your settings, in a drop-in file
Don’t edit 50unattended-upgrades. It’s a Debian conffile, so every package update that changes it would prompt you, and unattended upgrades skip packages with conffile prompts. Put your policy in a file that sorts after it instead.
How the two files combine:
- Lists (
Origins-Pattern,Package-Blacklist) are added to Debian’s. - Single values (
Mail,Automatic-Reboot, โฆ) replace Debian’s.
Create /etc/apt/apt.conf.d/52unattended-upgrades-local:
// /etc/apt/apt.conf.d/52unattended-upgrades-local
// Local policy. Read after Debian's 50unattended-upgrades:
// lists are appended to Debian's, single values override Debian's.
// --- What gets upgraded ----------------------------------------------------
// Debian's defaults already cover the point releases (label=Debian) and the
// security archive (label=Debian-Security). Add stable-updates too: it ships
// time-critical fixes between point releases (tzdata, ClamAV, certificates, ...).
Unattended-Upgrade::Origins-Pattern {
"origin=Debian,codename=${distro_codename}-updates,label=Debian";
};
// --- Reports -----------------------------------------------------------------
Unattended-Upgrade::Mail "ops@example.org";
// "on-change" while you build trust, "only-on-error" once you're comfortable
Unattended-Upgrade::MailReport "on-change";
Unattended-Upgrade::SyslogEnable "true";
// --- Robustness --------------------------------------------------------------
// Repair an interrupted dpkg run before upgrading
Unattended-Upgrade::AutoFixInterruptedDpkg "true";
// Upgrade in small steps so a shutdown can interrupt safely between them
Unattended-Upgrade::MinimalSteps "true";
// Never downgrade, even if a pin would allow it
Unattended-Upgrade::Allow-downgrade "false";
// --- Cleanup -----------------------------------------------------------------
// Remove old kernels automatically, so /boot never fills up
Unattended-Upgrade::Remove-Unused-Kernel-Packages "true";
// Remove dependencies that this run made unnecessary
Unattended-Upgrade::Remove-New-Unused-Dependencies "true";
// Leave older leftovers for a human ('apt autoremove')
Unattended-Upgrade::Remove-Unused-Dependencies "false";
// --- Reboots -----------------------------------------------------------------
// Reboot when /run/reboot-required exists, at the set time
Unattended-Upgrade::Automatic-Reboot "true";
Unattended-Upgrade::Automatic-Reboot-WithUsers "true";
Unattended-Upgrade::Automatic-Reboot-Time "04:00";Code language: PHP (php)
5.1 Choosing a reboot policy
A new kernel, or an update to libc or systemd, only takes effect after a reboot. needrestart can’t help there. Pick one of these on purpose:
| Policy | When | Settings |
|---|---|---|
| Automatic reboot in a window (recommended for most servers) | Stateless or redundant services, and anything without a human watching it | Automatic-Reboot "true" plus Automatic-Reboot-Time. Stagger the times across nodes of a cluster or HA pair so they never reboot together. |
| Manual reboot, monitored | Single critical systems (database primaries, hypervisors) | Automatic-Reboot "false", and an alert on /run/reboot-required (section 12). Without the alert, servers run vulnerable kernels for months. |
Automatic-Reboot-WithUsers "true" reboots even if someone is logged in. That’s right for servers. On a shared jump host, set it to "false".
6. Third-party repositories
Packages from other repositories are only upgraded if you list their origin. First find out how a repository identifies itself:
apt-cache policy
500 http://security.debian.org/debian-security trixie-security/main amd64 Packages
release v=13,o=Debian,a=stable-security,n=trixie-security,l=Debian-Security,c=main,b=amd64
origin security.debian.orgCode language: JavaScript (javascript)
The release line gives you the keys you can match on: o= origin, a= archive/suite, n= codename, l= label, c= component. The origin line gives the host, which you match with site=. Add the repositories to your drop-in:
Unattended-Upgrade::Origins-Pattern {
// Puppet agent (the repository is per major version, so no surprise major upgrades)
"site=apt.puppetlabs.com";
};Code language: PHP (php)
Think before adding agent repositories. Some products need a fixed upgrade order. Wazuh, for example, doesn’t support agents newer than the manager. If
packages.wazuh.comis an allowed origin on your agents, an agent can upgrade before the manager does. Either leave such repositories out and upgrade them deliberately, or exclude the packages as shown in section 7.
7. Excluding packages
Some packages must only be upgraded by a human, typically clustered or version-coupled software. There are two ways to exclude them.
Package-Blacklist in your drop-in. The entries are Python regular expressions matched from the start of the package name, so anchor them with $:
Unattended-Upgrade::Package-Blacklist {
"wazuh-manager$";
"wazuh-indexer$";
"wazuh-dashboard$";
"mariadb-server"; // matches mariadb-server and mariadb-server-core
};Code language: PHP (php)
apt-mark hold works for every APT tool, not just unattended-upgrades:
apt-mark hold wazuh-agent
apt-mark showhold
Don’t exclude the kernel. Excluding
linux-means kernel security fixes never get installed. A full disk is the usual reason people do it: new kernels and initramfs images go to/boot(not/tmp). KeepRemove-Unused-Kernel-Packages "true", and make/bootat least 1 GB on new installations.
8. Choose the time window
By default the upgrade runs around 06:00, with up to an hour of random delay. Move it into your maintenance window:
systemctl edit apt-daily-upgrade.timerCode language: CSS (css)
[Timer]
OnCalendar=
OnCalendar=*-*-* 03:00
RandomizedDelaySec=30m
The empty OnCalendar= clears Debian’s default before setting your own time. Keep the random delay, so a whole fleet doesn’t hit the mirror at the same second. Make sure the upgrade finishes before Automatic-Reboot-Time.
systemctl daemon-reload
systemctl list-timers 'apt-daily*'Code language: PHP (php)
9. needrestart: restart services automatically
After an update to OpenSSL, glibc or another library, running services keep using the old, vulnerable copy in memory until they restart. needrestart finds them after every APT run. When run non-interactively, as it is under unattended-upgrades, it only lists them by default, so tell it to restart them.
Create /etc/needrestart/conf.d/50-autorestart.conf:
# /etc/needrestart/conf.d/50-autorestart.conf
# Restart mode: (l)ist only, (i)nteractive, (a)utomatic
$nrconf{restart} = 'a';
# Never restart these automatically (regex on the unit name).
# Debian's defaults already exclude dbus, systemd-logind, display managers, getty, ...
$nrconf{override_rc}{qr(^mariadb)} = 0;
$nrconf{override_rc}{qr(^postgresql)} = 0;Code language: PHP (php)
Exclude services where a restart interrupts users or needs coordination, such as databases, cluster members, or VPN concentrators. needrestart still lists them, and you restart them in a window.
Check what needs restarting right now:
needrestart -r l # list only, change nothing
needrestart -b # machine-readable summary, including kernel statusCode language: PHP (php)
10. apt-listchanges: mail important news
apt-listchanges mails you the NEWS entries of upgraded packages. Maintainers use those to announce behaviour changes and required manual steps. Configure it in /etc/apt/listchanges.conf:
[apt]
frontend=mail
email_address=ops@example.org
which=news
confirm=false
headers=false
save_seen=/var/lib/apt/listchangesCode language: JavaScript (javascript)
which=news sends only the important notes, not every changelog line. Use both if you want the full changelogs too.
11. Testing
11.1 The configuration is what you expect
apt-config dump | grep -E '^(APT::Periodic|Unattended-Upgrade)::'
systemctl list-timers 'apt-daily*'Code language: PHP (php)
Both timers must be listed with a next run time, and the output must show your Mail, Automatic-Reboot and Origins-Pattern entries.
11.2 A dry run
unattended-upgrade --dry-run --debug 2>&1 | less
Look for these lines:
Allowed origins are: โฆ, which must include your additionsPackages that will be upgraded: โฆ- Packages listed as
kept backorblacklisted, which must be the ones you intended
11.3 A real run
unattended-upgrade -v
tail -n 50 /var/log/unattended-upgrades/unattended-upgrades.logCode language: JavaScript (javascript)
With MailReport "on-change", a run that upgraded something sends a report to ops@example.org.
11.4 Reboot handling
ls -l /run/reboot-required* 2>/dev/null && cat /run/reboot-required.pkgsCode language: JavaScript (javascript)
If the file exists and Automatic-Reboot is on, shutdown --show displays the scheduled reboot after the next run.
12. Monitoring
| Source | What it tells you |
|---|---|
/var/log/unattended-upgrades/unattended-upgrades.log | What was upgraded, kept back or skipped, and why |
/var/log/unattended-upgrades/unattended-upgrades-dpkg.log | The full dpkg output, which is the place to look when something failed |
journalctl -u apt-daily-upgrade.service | When the run started and finished, and its exit status |
| The mail reports | The summary, without logging in |
With Prometheus: the prometheus-node-exporter-collectors package exports apt_upgrades_pending and node_reboot_required through the textfile collector. Two alerts cover the failure modes that matter. Either upgrades stopped happening, or a reboot never came:
- alert: AptUpgradesPendingTooLong
expr: sum by (instance) (apt_upgrades_pending{job="node"}) > 0
for: 3d
labels:
severity: warning
annotations:
summary: "{{ $labels.instance }} has had pending upgrades for 3 days"
description: "unattended-upgrades isn't installing them: check origins, exclusions and the log."
- alert: NodeRebootRequired
expr: node_reboot_required{job="node"} > 0
for: 3d
labels:
severity: warning
annotations:
summary: "{{ $labels.instance }} has needed a reboot for 3 days"Code language: JavaScript (javascript)
apt_upgrades_pending also counts packages from origins you deliberately didn’t allow, so tune the alert or exclude those origins in the expression.
13. Troubleshooting
| Symptom | Cause / fix |
|---|---|
| Nothing happens at all | The timers are disabled (systemctl list-timers 'apt-daily*'), or 20auto-upgrades is missing or set to "0" |
Log: Package X has conffile prompt and needs to be upgraded manually | Expected behaviour. Run apt upgrade by hand and decide on the config file. |
| Packages stay “kept back” | Their origin isn’t allowed (compare the dry run’s Allowed origins with apt-cache policy), they’re held, or they need new dependencies that a plain upgrade won’t install |
| No mails | No MTA or /usr/sbin/sendmail, MailReport set to only-on-error, or a typo in the value. Check /var/log/mail.log or journalctl -u postfix. |
dpkg was interrupted | AutoFixInterruptedDpkg repairs it on the next run. To fix it now, run dpkg --configure -a. |
| Services not restarted | needrestart is in list mode, or the service matches an override_rc rule. Check with needrestart -r l. |
/boot full | Old kernels are piling up. Check Remove-Unused-Kernel-Packages, run apt autoremove --purge, and plan a larger /boot |
14. Checklist
- โ
unattended-upgrades,needrestartandapt-listchangesare installed, and a working MTA delivers mail - โ
20auto-upgradesenables the update, download, upgrade and autoclean jobs - โ Debian’s
50unattended-upgradesis untouched, and all local settings live in52unattended-upgrades-local - โ Origins cover security, point releases and
-updates. Third-party repositories are added deliberately. - โ Exclusions are anchored regexes or
apt-mark hold. The kernel is not excluded. - โ A reboot policy is chosen: automatic in a staggered window, or manual with an alert
- โ The upgrade window (
apt-daily-upgrade.timer) ends before the reboot time - โ needrestart runs in automatic mode, with critical services excluded on purpose
- โ
apt-listchangesmails NEWS entries - โ The dry run shows the expected origins and packages, and a real run produced a mail report
- โ Monitoring alerts on pending upgrades and pending reboots