An unpatched Ubuntu server is the easiest way to lose a website. Security fixes land almost every week, and attackers scan for the hole each patch closes within hours. Automatic security updates on Ubuntu close that gap for you: the server downloads and installs security patches on its own, usually overnight, while you sleep.
The catch is that “automatic” can also mean “surprise”. A kernel update that wants a reboot, or a package update that restarts a service at the wrong moment, can take a site down at 3 a.m. This guide sets it up the safe way: security patches only, no surprise reboots, a dry run before you trust it, and a way back when something goes wrong. It works on Ubuntu 22.04 and 24.04, on a VPS or a bare-metal box.
Why automatic updates beat manual patching
Most server owners do not patch on a schedule. They patch when they remember, or after something breaks, and a weekly manual update easily slips to monthly, then quarterly.
Ubuntu security updates are small and focused. They fix vulnerabilities; they do not add features or change how a program behaves. That makes them the safest kind of update to hand over to a machine.
The risk of patching late is concrete: bots scan the whole internet for known flaws within hours of a fix being published, and any reachable server gets probed. The risk of patching automatically is manageable, and the rest of this guide keeps it that way. Automation does the boring part; you keep the decisions that matter, like when to reboot and which packages to pin.
What unattended-upgrades actually installs
Ubuntu ships a tool called unattended-upgrades. It runs on a timer, checks for new packages, and installs the ones you allow. The unattended-upgrades Ubuntu package is usually already installed on Ubuntu Server, so on many systems the work is configuration, not installation.
Out of the box it installs security updates only. It does not pull in feature updates, new package versions, or distribution upgrades, so a server on 22.04 stays on 22.04.
It also handles small details well. It keeps your edited config files instead of overwriting them, it can remove old kernels and unused dependencies, and it writes a log of everything it did. If you want the full walkthrough of the tool itself, our guide to setting up automatic security updates on Ubuntu with unattended-upgrades covers the install step by step.
Install and enable automatic security updates on Ubuntu
The setup takes about five minutes over SSH, as a user with sudo.
- Update the package lists and install the tool.
sudo apt update && sudo apt install unattended-upgrades - Enable it.
sudo dpkg-reconfigure -plow unattended-upgradesAnswer Yes. This creates/etc/apt/apt.conf.d/20auto-upgradeswith both switches on. - Check the timers are active.
systemctl list-timers --all | grep aptYou should seeapt-daily.timerandapt-daily-upgrade.timer, each with a next run time. - Confirm the schedule.
apt-config dump APT::Periodic::shows the values the timers read.
Limit updates to security patches only
Open the unattended upgrades config file at /etc/apt/apt.conf.d/50unattended-upgrades. The Origins-Pattern section decides what gets installed, and this is the one place where a wrong line can change your server in ways you did not ask for. Make sure only the security line is uncommented:
Unattended-Upgrade::Allowed-Origins {
"${distro_id}:${distro_codename}-security";
};
Keep the lines for -updates, -proposed, and -backports commented out. The -updates pocket brings bug fixes and minor version bumps that can change behaviour your site depends on, so keep those manual and read the changelog first.
While you are in the file, switch on two clean-up options:
Unattended-Upgrade::Remove-Unused-Dependencies "true";
Unattended-Upgrade::Remove-Unused-Kernel-Packages "true";
Old kernels pile up over years, and each one eats disk space on /boot. A full /boot partition is a classic cause of updates failing halfway through.
If your site depends on one exact package version, pin it first: sudo apt-mark hold php8.3 tells the updater to skip that package, so a version jump cannot sneak in overnight. Check holds with apt-mark showhold. One warning: a hold also blocks that package’s security fixes, so review holds every few months.
Set the schedule and stop surprise reboots
By default the upgrade timer runs once a day, in the early hours. Check when it fires with systemctl list-timers apt-daily-upgrade.timer, and shift it with a timer override if the window lands on your busiest hour.
Reboots are the part people fear most, and the default is already on your side: Unattended-Upgrade::Automatic-Reboot is "false" unless you change it, so kernel updates install but wait for a manual reboot. Leave it that way.
If you do want automatic reboots, set the value to "true" and add a fixed time:
Unattended-Upgrade::Automatic-Reboot "true";
Unattended-Upgrade::Automatic-Reboot-Time "03:30";
Pick a low-traffic hour, and confirm every service your site needs starts on boot: systemctl is-enabled nginx php8.3-fpm mysql should answer enabled for each one.
Mail reports are worth setting up too. Add your address and ask for reports only on errors:
Unattended-Upgrade::Mail "[email protected]";
Unattended-Upgrade::MailReport "only-on-error";
This needs a working mail setup on the server. Patching is one layer of defence, and a firewall is another, so if you have not set one up yet, read our guide to setting up a firewall with UFW on Ubuntu Server 24.04.
Test the setup before you trust it
Never switch on automation and hope for the best. Run a dry run first:
sudo unattended-upgrades --dry-run --debug
The output shows exactly which packages would be installed and which would be skipped, without changing anything. If the list includes a package you expected held back, fix the config now, while nothing is at stake.
Then do the first real run by hand: sudo unattended-upgrades -v. Watch the output, wait for it to finish, then load your sites and click through them. A homepage that loads is not enough; check a login page and any form or checkout flow your visitors actually use.
Better still, test on a staging copy first: a cheap test VPS with the same stack, the same config, and the update run there before production.
After the first automatic run, check each site on the box. If you run several sites from one server, our guide to setting up Nginx server blocks on Ubuntu 24.04 shows how they are laid out.
Check that updates are actually running
Automation you never check is a hope, not a system. The log tells you the truth:
less /var/log/unattended-upgrades/unattended-upgrades.log
Look for the upgraded packages and scan for errors. If the log has not been written to in a week, the timer is not firing.
Two quick checks confirm the whole chain. First, systemctl status apt-daily-upgrade.timer shows the next scheduled run. Second, sudo unattended-upgrades --dry-run should report nothing to do on a system that is current. Put a monthly reminder in your calendar to glance at the log; five minutes a month is the difference between “updates are automatic” and “updates were automatic until something silently stopped”.
When an update breaks a site
Do not roll back everything. Start by finding what changed: the unattended-upgrades log lists the exact packages and versions it installed.
Downgrade the single package that broke things: find the previous version with apt-cache policy packagename, install it with sudo apt install packagename=old-version, and hold it until you know why the new version broke your setup.
If a service will not start, check its own log first: journalctl -u nginx, journalctl -u php8.3-fpm, and the MySQL error log answer most questions in seconds. Most cases turn out to be a service that failed to restart, not a broken package.
If the site is WordPress, remember that plugins and themes are not covered by unattended-upgrades at all. Those need their own update routine, and our guide to bulk updating WordPress plugins with WP-CLI without breaking your site covers that with the same safety-first approach.
If the damage is wider than one package, restore from backup. This is the moment backups earn their keep, so take a snapshot of the server before you enable automatic updates.
Frequently asked questions
Will automatic security updates reboot my server?
No, not by default. Automatic reboot is switched off unless you turn it on, so kernel updates install and wait for a manual reboot. Only enable it if you have set a reboot time and confirmed every service starts on boot.
Do automatic updates upgrade Ubuntu to a new release?
No. Unattended-upgrades installs packages from your current release only. Moving to a new Ubuntu release is a separate, manual step with do-release-upgrade, and it never runs on its own.