Setting up automatic security updates on Ubuntu is one of the highest-impact, lowest-effort hardening steps you can take on a server. Most real-world compromises do not use zero-day exploits; they use known vulnerabilities for which a patch already exists but was never installed. The unattended-upgrades package closes that gap by downloading and applying security updates every day without you logging in. This guide shows how to install it, configure it properly, control reboots, and verify it is actually working. This article covers How to Set Up Automatic Security in detail.
Why Automatic Security Updates on Ubuntu Matter – How to Set Up Automatic Security
Ubuntu publishes security fixes for the kernel, OpenSSL, sudo, web servers and hundreds of other packages through the -security repository. On a manually maintained VPS it is easy to fall weeks behind, especially if you manage several machines. With automatic security updates on Ubuntu handled by unattended-upgrades, critical patches are usually applied within 24 hours of release. You keep control over the risky parts: you can allow or block automatic reboots, exclude specific packages and decide whether only security updates or all updates are installed.
Prerequisites – How to Set Up Automatic Security
- An Ubuntu 20.04, 22.04 or 24.04 server with
sudoaccess. - Regular backups or snapshots, as with any system change.
- Optional: a mail transport such as Postfix if you want email reports.
Step 1: Install unattended-upgrades
On many Ubuntu server installs the package is already present, but install it explicitly to be sure, together with the update notifier utilities:
sudo apt update
sudo apt install unattended-upgrades apt-listchanges -y
Step 2: Enable the Automatic Update Timers
Create the configuration file /etc/apt/apt.conf.d/20auto-upgrades with the following content:
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "1";
APT::Periodic::Download-Upgradeable-Packages "1";
APT::Periodic::AutocleanInterval "7";
The first two lines are the essential ones: refresh package lists daily and apply unattended upgrades daily. Alternatively, run sudo dpkg-reconfigure -plow unattended-upgrades and answer Yes to generate the file automatically. The work is done by two systemd timers, which you can check with:
systemctl status apt-daily.timer apt-daily-upgrade.timer

Step 3: Configure Which Updates Are Installed
The main configuration lives in /etc/apt/apt.conf.d/50unattended-upgrades. By default, only the security origin is enabled:
Unattended-Upgrade::Allowed-Origins {
"${distro_id}:${distro_codename}-security";
};
Leave this as it is for production servers: regular feature updates keep flowing through your normal maintenance process, while security patches apply themselves. Inside the same file you can also blacklist packages that must never change without testing, for example a database server:
Unattended-Upgrade::Package-Blacklist {
"mysql-server";
};
Step 4: Control Automatic Reboots
Some updates, especially kernel updates, only take effect after a reboot. By default unattended-upgrades will not reboot your server. If the machine can tolerate a scheduled restart, enable it at a quiet hour:
Unattended-Upgrade::Automatic-Reboot "true";
Unattended-Upgrade::Automatic-Reboot-Time "03:30";
On busy production systems, keep reboots manual and watch for the /var/run/reboot-required file instead.
Step 5: Enable Email Notifications
To receive a report whenever packages are upgraded, add your address to the same file:
Unattended-Upgrade::Mail "[email protected]";
Unattended-Upgrade::MailReport "on-change";
This requires a working local mail setup. A lightweight option is a send-only Postfix configuration, and you should combine updates with login protection such as Fail2Ban for SSH for a sensible baseline.
Step 6: Test with a Dry Run
Before trusting the automation, simulate a run. The debug output shows exactly which packages would be downloaded and upgraded:
sudo unattended-upgrades --dry-run --debug
If the simulation completes without errors, force a real run once with sudo unattended-upgrades and watch it complete.
Step 7: Verify It Keeps Working
Every run is logged. Check recent activity any time with:
sudo tail -n 50 /var/log/unattended-upgrades/unattended-upgrades.log
ls -l /var/log/apt/history.log
How the Daily Upgrade Process Works
Understanding the machinery helps you trust it. Twice a day, the apt-daily.timer wakes up and refreshes the package lists from your configured repositories. Separately, apt-daily-upgrade.timer runs the upgrade service once a day at a semi-randomized time, so that thousands of Ubuntu machines do not all hit the mirrors at the same moment. During that run, unattended-upgrades downloads only the packages that match your allowed origins, verifies their signatures, installs them with the same dependency logic apt uses interactively, and cleans up old kernel versions so the boot partition does not fill up. If anything goes wrong mid-run, the failure is written to the log and the package manager is left in a consistent state; a broken dpkg lock or an interrupted download simply means the remaining updates are retried on the next scheduled run. You can watch the timers’ next scheduled executions at any time:
systemctl list-timers apt-daily*
On servers that also run third-party repositories, such as Docker or a vendor monitoring agent, those packages are ignored by default because their origins are not in your allowed list. That is the safe behavior: vendor repositories follow their own release cadence and are best upgraded deliberately, after reading their changelogs.
Troubleshooting
No updates are being applied. Confirm both timers are active and that APT::Periodic::Unattended-Upgrade is set to "1" with apt-config dump | grep -i periodic.
A package was held back. Upgrades that would remove packages or change dependencies are skipped by design. Review the log, then apply them manually during your next maintenance window.
Emails never arrive. Test local delivery with echo test | mail -s test [email protected] and check the mail log; the update system itself does not send mail without a working MTA. If attacks continue despite patching, consider adding a firewall layer such as the one described in our CSF on Ubuntu guide.
Conclusion
Automatic security updates on Ubuntu through unattended-upgrades remove the most common cause of server compromise: the unpatched known vulnerability. Install it, restrict it to the security repository, decide your reboot policy and check the log once in a while. For the official reference, see the Ubuntu community documentation on automatic security updates.