Security and hardening · Beginner · 9 min
How to Turn On Automatic Security Updates on Ubuntu 26.04
By Padding · Updated 15 Nov 2026
Ubuntu 26.04.1 LTS · unattended-upgrades
You will check that unattended-upgrades installs security fixes by itself on Ubuntu 26.04, tune it to reboot at a quiet hour when a kernel update needs it, and read its logs to confirm it works.
On this page
Most break-ins use a flaw that already has a fix. The window between a fix being published and you installing it is when you are exposed. Ubuntu's unattended-upgrades package closes that window by installing security updates in the background, every day, with nobody logged in.
In this tutorial you will make sure it is installed and on, look at which updates it is allowed to install, set a quiet-hour reboot for the updates that need one, and run a dry run to see what it would do. You do not have to install anything on most Ubuntu servers, because the package is included, but you will check.
Step 1 · Install the package and check it is on
sudo apt-get update
sudo apt-get install -y unattended-upgradesIf it was already installed, apt says so and changes nothing. Ubuntu enables it through a small file. Print it:
cat /etc/apt/apt.conf.d/20auto-upgradesThe file contains two lines:
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "1";The first refreshes the list of available packages once a day, and the second runs unattended-upgrade once a day. The number is a count of days, and 0 turns the job off. If the file is missing or shows "0", write it. This command replaces the whole file. That is safe here because the file normally holds only these settings, but if yours has extra APT::Periodic lines, add them to the command first:
sudo tee /etc/apt/apt.conf.d/20auto-upgrades > /dev/null <<'CONF'
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "1";
APT::Periodic::AutocleanInterval "7";
CONFThe AutocleanInterval line deletes downloaded package files that are no longer needed once a week.
Check it worked
Ask apt which settings it reads:
apt-config dump | grep -E '^APT::Periodic'The output includes APT::Periodic::Update-Package-Lists "1"; and APT::Periodic::Unattended-Upgrade "1";.
On a server with systemd, two timers run the job. Check that they are scheduled:
systemctl list-timers 'apt-daily*'You see apt-daily.timer and apt-daily-upgrade.timer with the time of their next run. Their times are randomised slightly, so servers do not all hit the mirrors at the same minute.
Step 2 · See what it is allowed to install
The main settings file is /etc/apt/apt.conf.d/50unattended-upgrades. Print it without its comments:
grep -vE '^\s*//|^\s*$' /etc/apt/apt.conf.d/50unattended-upgradesThe Allowed-Origins block lists where updates may come from. By default it holds the main Ubuntu release and its -security pocket, plus the security pockets of Ubuntu Pro's extended maintenance repositories. Ordinary feature updates from -updates stay out, so the automatic job only installs fixes for known vulnerabilities, which carry the lowest risk of breaking something.
Do not edit 50unattended-upgrades itself. A package update could ask you about the changed file. Put your changes in a separate file that is read after it. Files in /etc/apt/apt.conf.d/ are read in alphabetical order, and later settings win, so a name that sorts after 50 works.
Step 3 · Choose how it handles reboots
Some updates, mainly the kernel and core libraries, only take effect after a reboot. By default unattended-upgrades never reboots. The server then runs the old kernel until you restart it. On a server where a short, scheduled restart is acceptable, let it reboot at a quiet hour. A reboot interrupts every service on the machine for a minute or so, so skip this on a machine where that is not acceptable and reboot by hand instead.
sudo tee /etc/apt/apt.conf.d/52unattended-upgrades-local > /dev/null <<'CONF'
// Reboot only when an installed update needs it, and only at this time.
Unattended-Upgrade::Automatic-Reboot "true";
Unattended-Upgrade::Automatic-Reboot-Time "04:00";
// Clean up libraries and kernels that nothing needs any more.
Unattended-Upgrade::Remove-Unused-Dependencies "true";
CONFAutomatic-Reboot-Time uses the server's clock, which is UTC unless you changed it. Pick an hour when your traffic is lowest. To get an email report instead of or as well as a reboot, install a mail tool and set Unattended-Upgrade::Mail. The mail setup is outside this tutorial.
Check it worked
apt-config dump | grep -E 'Unattended-Upgrade::(Automatic-Reboot|Remove-Unused)'The output shows Unattended-Upgrade::Automatic-Reboot "true";, Unattended-Upgrade::Automatic-Reboot-Time "04:00"; and Unattended-Upgrade::Remove-Unused-Dependencies "true";.
Step 4 · Do a dry run
A dry run goes through the whole process, including downloading, but installs nothing. Add -d to see the reasoning:
sudo unattended-upgrade --dry-run -d 2>&1 | tail -n 12On a server that is fully patched, the output ends with lines something like InstCount=0 DelCount=0 BrokenCount=0 and upgrade result: True All upgrades installed. When security updates are waiting, a line such as Packages that will be upgraded: lists them first, and InstCount is above 0. Because it is a dry run, nothing is installed. Leave out | tail -n 12 to read the whole output, which also names the allowed origins it checked.
Troubleshooting
dpkg was interrupted, you must manually run 'sudo dpkg --configure -a': an earlier package operation was cut off. Run that command, then the dry run again.- Updates are listed by
apt list --upgradablebut the dry run skips them: they come from a pocket that is not inAllowed-Origins, such as-updates. That is the default and is intended. Install those yourself withsudo apt update && sudo apt upgrade. - The job never seems to run: on a server with systemd, check
systemctl status apt-daily-upgrade.timer. If the timer is inactive,sudo systemctl enable --now apt-daily-upgrade.timerstarts it.
Step 5 · Read the logs
The job writes a log of everything it does:
sudo ls /var/log/unattended-upgrades/
sudo tail -n 30 /var/log/unattended-upgrades/unattended-upgrades.logEach run adds lines that say when it started, which origins it allowed, and either the packages it installed or that it found nothing to upgrade. Check this log a day after you turn the job on, and again after a week.
When a reboot is needed and you have not enabled automatic reboots, Ubuntu creates the file /var/run/reboot-required:
test -f /var/run/reboot-required && cat /var/run/reboot-required || echo "No reboot needed."If it prints *** System restart required ***, restart at a time that suits you with sudo reboot. The file /var/run/reboot-required.pkgs names the packages that asked for it.
Next steps
- Close every port you do not use:
/tutorials/set-up-ufw-firewall-ubuntu-26-04. - Stop password guessing:
/tutorials/block-brute-force-logins-with-fail2ban. - See how the whole server scores:
/tutorials/audit-a-server-with-lynis. - The reference is Ubuntu's server guide section on automatic updates, at documentation.ubuntu.com/server.
Related tutorials
- How to Do the Initial Setup of a New Ubuntu 26.04 ServerYou will take a fresh Ubuntu 26.04 server from a root-only login to an updated machine with a daily-use account, your SSH key on it, a firewall and a known clock.
- How to Schedule Jobs with Cron on LinuxYou will schedule a command to run every minute, then on a real timetable, read the cron syntax, and learn why a job that works in your shell can fail under cron.
Need this done for you?
Padding does this work for growing companies, from the first diagnosis to a system that keeps working.
Get new tutorials