How to Set Up Automatic Security Updates on Ubuntu with Unattended-Upgrades
Security patches land often, and a server that waits weeks for a manual update stays open to known flaws for all that time. Setting up automatic security updates Ubuntu owners can trust takes about fifteen minutes, and it removes the most common reason small servers stay unpatched. This guide shows how to install Unattended-Upgrades, pick exactly what it installs, control reboots, and check that it runs.
Unattended-Upgrades is a small tool that runs on a schedule, downloads packages from the security archive, and installs them without asking you to type yes each time. It does not replace a full maintenance routine. It covers the urgent fixes so a missed weekend does not turn into a missed month. For a wider first-week routine, read our first 10 things to do after buying a VPS security checklist, which puts patching next to firewall and SSH steps.
What Automatic Security Updates on Ubuntu Install by Default
By default, Unattended-Upgrades installs packages from the Ubuntu security archive only. Ubuntu security updates arrive through that archive, and the tool pulls only from there unless you widen the list. That means kernel security fixes, OpenSSL fixes, and patches for other packages with a security advisory. It does not install every available update, and it does not upgrade your release to a new Ubuntu version. That narrow scope is the point: security fixes are small, tested against your release, and far less likely to change how your software behaves than a full upgrade.
You can widen the scope to regular updates too, but on a production server that trade is rarely worth it. A feature update to a web server or database can change a default setting or drop an old option. Keep automatic installs limited to security updates, then schedule feature updates by hand when you can watch the result and roll back if needed.
Install Unattended-Upgrades and Check the Timer
On most Ubuntu server images the package is already present. Install it and make sure the timer is active with these commands:
sudo apt updatesudo apt install -y unattended-upgrades apt-listchangessudo systemctl enable --now unattended-upgradessudo systemctl status unattended-upgrades
Ubuntu runs the job through a systemd timer, not a cron entry you edit by hand. Check it with systemctl list-timers --all | grep apt. You should see apt-daily.timer and apt-daily-upgrade.timer. If either timer shows as inactive, enable it with sudo systemctl enable --now apt-daily.timer apt-daily-upgrade.timer. The download step and the install step run at different times, which spreads load and gives the package lists time to refresh before installs start.
Unattended-Upgrades Configuration You Should Review
The main file is /etc/apt/apt.conf.d/50unattended-upgrades. Open it and check three blocks. First, the Unattended-Upgrade::Allowed-Origins list should include the security lines for your release, such as "${distro_id}:${distro_codename}-security". Second, the package blacklist lets you hold back a package you never want touched automatically, for example a database version your app pins. Add it like this:
Unattended-Upgrade::Package-Blacklist { "mysql-server"; };
Third, check the mail setting. Unattended-Upgrade::Mail can send a report to an address you read, and Unattended-Upgrade::MailReport set to "only-on-error" keeps the noise down. Without mail, check the logs instead, which the next section covers. If you run a web server, pair this step with a firewall review in our guide to configuring UFW firewall rules for a web server so patching and network filtering move together.
Control Automatic Reboots So Updates Do Not Surprise You
Some security updates, kernel updates included, only take effect after a reboot. Unattended-Upgrades can reboot for you, but the default is off, and on a live server that default is usually right. A surprise reboot at peak traffic is worse than a patch that waits one day for a planned restart. Set the reboot options to match your server:
Unattended-Upgrade::Automatic-Reboot "false";Unattended-Upgrade::Automatic-Reboot-Time "03:00";
The automatic reboot Ubuntu option is off by default for a reason. If you do allow automatic reboots, pick a low-traffic hour and set Automatic-Reboot-WithUsers to "false" so a logged-in session blocks the reboot. For a server that must stay up, leave reboots off and add a weekly reminder to reboot after kernel updates. Check whether a reboot is pending with ls /var/run/reboot-required and see which packages asked for it with cat /var/run/reboot-required.pkgs.
Test the Setup with a Dry Run
Never trust a config file you have not run. A dry run shows what would install without changing anything:
sudo unattended-upgrades --dry-run --debug
Read the output for lines that say a package would be upgraded and lines that say a package is blacklisted. If the run reports nothing, check that your package lists are fresh with sudo apt update and that the security origin lines match your release name from lsb_release -c. A common mistake is copying a config from another release, so the origin lines never match and nothing ever installs. That silent failure is worse than an error, because the server looks maintained while it is not.
Read the Logs and Prove Updates Actually Happen
After the first scheduled run, check /var/log/unattended-upgrades/unattended-upgrades.log. Look for a run date, a list of packages installed, and a clean finish. A log that only shows downloads and no installs points at a config problem, often a missing origin or a held package blocking the run. The dpkg log at /var/log/dpkg.log gives a second view of what changed and when, which helps when a service starts acting up and you need to know if an update landed that night.
Pair patching with intrusion checks. Updates close known holes, but they do not tell you if someone already got in. Our Fail2ban setup guide for SSH and Nginx on Ubuntu adds brute force protection, and our SSH hardening guide for Ubuntu 24.04 covers the login settings that patching alone cannot fix.
What Automatic Updates Should Never Touch
Keep three things out of automatic installs. First, release upgrades: moving from one Ubuntu release to another changes libraries across the system and needs a backup and a test window. Second, packages your app pins to an exact version, such as a database or language runtime your code was tested against. Third, kernel versions on servers with third-party drivers that build against a specific kernel, where a new kernel can leave a driver unloaded after reboot. Hold those with apt holds or the blacklist, and update them by hand.
Also keep a backup habit. Automatic updates are safe in the normal case, but a backup turns a rare bad update from an outage into a restore job. Snapshot the VPS or back up the data and config before you rely on any automatic change, and test a restore at least once so you know the backup works when you need it.
When Automatic Updates Are Not Enough
Automatic security updates cover packages from Ubuntu archives. They do not patch web apps you installed by hand, WordPress plugins, Docker images, or code you deployed from a repository. Those need their own update routine: plugin updates on a schedule, image rebuilds for containers, and deploys for your own code. Treat the Ubuntu layer as one layer only, and list every other layer your server runs so none of them drifts unpatched while the operating system stays current.
Set a monthly check even with automation in place. Once a month, review the unattended-upgrades log, check for a pending reboot, confirm no package has been held for months, and run sudo apt update && apt list --upgradable to see what sits outside the security scope. That short review keeps automation honest and catches the quiet failures that no alert will flag.