On a server, security updates should not depend on someone remembering them. Ubuntu and Debian ship unattended-upgrades for this: the package installs updates automatically in the background and can send an e-mail with the result if you wish. This guide applies to current Ubuntu LTS releases (22.04, 24.04, 26.04) and Debian 12/13.
1. Install and enable the package
On Ubuntu, unattended-upgrades is usually preinstalled; on minimal Debian installations it often is not:
sudo apt update
sudo apt install unattended-upgrades apt-listchanges
sudo dpkg-reconfigure -plow unattended-upgrades
Answer the question in the dialog with Yes. This creates the file /etc/apt/apt.conf.d/20auto-upgrades:
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "1";
The 1 stands for “daily”. Nowadays this is no longer run by cron but by the systemd timers apt-daily.timer (download package lists) and apt-daily-upgrade.timer (install updates). When they will run next is shown by:
systemctl list-timers 'apt-daily*'
2. Define what gets updated
The actual configuration is in /etc/apt/apt.conf.d/50unattended-upgrades. On Ubuntu only the security repository is active by default:
Unattended-Upgrade::Allowed-Origins {
"${distro_id}:${distro_codename}";
"${distro_id}:${distro_codename}-security";
"${distro_id}ESMApps:${distro_codename}-apps-security";
"${distro_id}ESM:${distro_codename}-infra-security";
// "${distro_id}:${distro_codename}-updates";
};
If you also want regular bug fixes to be installed automatically, remove the two slashes in front of the -updates line. On Debian the section is called Unattended-Upgrade::Origins-Pattern; the principle is the same.
Individual packages can be excluded, for instance when an update should be supervised by hand:
Unattended-Upgrade::Package-Blacklist {
"mariadb-server";
"linux-image-.*";
};
3. Notification by e-mail
In the same file, enter the recipient address and define when a mail is sent:
Unattended-Upgrade::Mail "admin@example.org";
Unattended-Upgrade::MailReport "on-change";
always– after every runon-change– only if something was installedonly-on-error– only on errors
For the mail to actually go out, the server needs a program that provides mail and a route to the mail server. For plain sending through an existing SMTP account, msmtp is sufficient:
sudo apt install bsd-mailx msmtp-mta
The SMTP credentials then go into /etc/msmtprc. A quick test: echo "Test" | mail -s "Test mail" admin@example.org
4. Clean-up and automatic reboot
Kernel updates only take effect after a reboot. Whether one is needed is indicated by the file /var/run/reboot-required. If you want the server to reboot automatically at night, set:
Unattended-Upgrade::Remove-Unused-Kernel-Packages "true";
Unattended-Upgrade::Remove-Unused-Dependencies "true";
Unattended-Upgrade::Automatic-Reboot "true";
Unattended-Upgrade::Automatic-Reboot-Time "04:00";
On servers that must not reboot unnoticed, leave Automatic-Reboot at false and reboot by hand after receiving the mail.
5. Dry run and logs
Whether the configuration is correct is shown by a trial run that installs nothing:
sudo unattended-upgrade --dry-run --debug
What actually happened is recorded in /var/log/unattended-upgrades/unattended-upgrades.log, the dpkg output in unattended-upgrades-dpkg.log in the same directory.
Addition: staying informed about all updates
unattended-upgrades only installs what the configuration allows. Apticron informs you by e-mail about the remaining available updates – so nothing slips through.
Originally published in 2011 for Ubuntu 10.04, completely revised in November 2026.