Skip to main content
A strong digital foundation for your business.

Knowledge Base

Practical guides that make your hosting, domain and virtual server services easier to understand.

Automatic security updates and rebooting after a kernel update

Getting security patches onto your server without delay is the cheapest way to reduce the risk of a compromise. In this guide you will automate security-only updates on Ubuntu, Debian and AlmaLinux, learn how to tell whether a reboot is needed after a kernel update, and plan that reboot in a controlled way.

What to automate and what to plan

Security updates are small, targeted patches released to close a known vulnerability; they rarely change behavior. That is why installing them automatically is far less risky than leaving the vulnerability open on your server for weeks. Major version upgrades (for example, moving from Ubuntu 24.04 to 26.04 or from Debian 12 to 13), on the other hand, change configuration files, PHP and database versions, and service behavior. Never do these automatically; take a backup and a snapshot first and plan them for a maintenance window.

Update typeExampleRecommended approach
Security patchFixes for OpenSSL, OpenSSH, sudo, glibcAutomatic (unattended-upgrades, dnf-automatic)
Kernel updatelinux-image on Ubuntu and Debian, kernel packages on AlmaLinuxAutomatic installation, planned reboot
Bug-fix updatesDebian point release updates, Ubuntu's -updates pocketManually at regular intervals, or automatic by deliberate choice
Major version upgradeUbuntu 24.04 → 26.04, Debian 12 → 13Planned, with a snapshot and a backup; or a clean install
Application layerWordPress, control panel, Docker imagesWith the application's own tools, tracked separately

Kernel updates are a special case: even when the package is installed automatically, the new kernel only takes effect when the server reboots. A server that is never rebooted keeps running the old, vulnerable kernel even though the update looks installed.

Ubuntu and Debian: installing unattended-upgrades

On Ubuntu server installations, unattended-upgrades is usually already present; on Debian it typically has to be installed by hand. The commands below are safe in both cases: if the package is already installed, only the configuration step does anything. apt-listchanges shows the changelogs of updated packages and is optional.

Bash
sudo apt update
sudo apt install unattended-upgrades apt-listchanges
sudo dpkg-reconfigure -plow unattended-upgrades
# Enabled? Both lines should show the value "1"
apt-config dump | grep -E '^APT::Periodic::(Update-Package-Lists|Unattended-Upgrade) '

When you answer the dpkg-reconfigure question with Yes, the file /etc/apt/apt.conf.d/20auto-upgrades is created with the following content. The first line refreshes the package lists every day, and the second runs the automatic installation daily:

Text
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "1";
Info

Do not remove or stop the open-vm-tools package during or after updates. Client area operations such as safe shutdown, password reset, network settings and disk expansion rely on VMware Tools inside the server. Updating the package is fine; what matters is that it stays installed and running.

50unattended-upgrades: sources, reboots and scheduling

The repositories that automatic updates come from are defined in /etc/apt/apt.conf.d/50unattended-upgrades. Ubuntu keeps this list in Allowed-Origins; the ${distro_id} and ${distro_codename} variables in these lines are replaced at run time with the distribution name and the release codename. In the default list, the security pocket and the ESM repositories used by Ubuntu Pro subscribers are enabled, while the -updates line stays commented out:

Text
// /etc/apt/apt.conf.d/50unattended-upgrades (Ubuntu)
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";
};

Debian does the same job with Origins-Pattern. Besides the security repository, the default list also covers the stable fixes Debian ships with point releases; these are conservative updates as well:

Text
// /etc/apt/apt.conf.d/50unattended-upgrades (Debian 12/13)
Unattended-Upgrade::Origins-Pattern {
        "origin=Debian,codename=${distro_codename},label=Debian";
        "origin=Debian,codename=${distro_codename},label=Debian-Security";
        "origin=Debian,codename=${distro_codename}-security,label=Debian-Security";
};

Only add sources you trust to these lists. Packages from third-party repositories such as Docker or Node.js are not updated automatically by default; you can see which source a package comes from with a command such as apt-cache policy docker-ce.

Keep reboot settings in a separate file

If you edit 50unattended-upgrades directly, you may be asked about a configuration file conflict when the package is updated. Put your own settings in a file whose name sorts later alphabetically. APT reads the files in this directory in name order, and for single-value settings the last value read wins:

Text
// /etc/apt/apt.conf.d/52unattended-upgrades-local
// Automatic reboot when required (default: "false")
Unattended-Upgrade::Automatic-Reboot "false";
// If you choose "true": reboot time and behavior with open sessions
Unattended-Upgrade::Automatic-Reboot-Time "04:00";
Unattended-Upgrade::Automatic-Reboot-WithUsers "true";
// Remove old, unused kernel packages
Unattended-Upgrade::Remove-Unused-Kernel-Packages "true";

With Automatic-Reboot enabled, the server reboots on its own at the specified time after an update that requires it, such as a kernel update. The time is interpreted in the server's local time zone; check with timedatectl that the time zone is correct (for example, Europe/Istanbul). If you set Automatic-Reboot-WithUsers to "false", no reboot happens while a session is open; if you keep sessions open permanently with tmux or screen, this can mean the reboot never happens at all.

Recommendation

On servers that run a database or are sensitive to downtime, leave Automatic-Reboot at "false" and reboot yourself using the planned steps below. On stateless web and test servers, an automatic reboot scheduled for the night is a reasonable choice.

Dry runs, logs and scheduling

After changing the settings, do a dry run to see what would be installed without installing anything. Two systemd timers drive the automatic runs: apt-daily.timer refreshes the package lists and downloads packages, and apt-daily-upgrade.timer performs the installation. You can also add these checks to your first 30 minutes checklist.

Bash
# Shows what would be installed without installing anything
sudo unattended-upgrade --dry-run --debug
# Log of recent automatic runs
sudo tail -n 30 /var/log/unattended-upgrades/unattended-upgrades.log
# Timers: last and next run times
systemctl list-timers 'apt-daily*'

By default, apt-daily-upgrade.timer runs around 06:00 with a random delay of up to an hour. If you want installations to happen at your lowest-traffic hour, override the timer; the first, empty OnCalendar= line clears the default time:

INI
# Write this into the file opened by sudo systemctl edit apt-daily-upgrade.timer
[Timer]
OnCalendar=
OnCalendar=*-*-* 03:30
RandomizedDelaySec=15m

AlmaLinux 9: dnf-automatic

On AlmaLinux, dnf-automatic does the same job. Because the AlmaLinux repositories publish security advisories (errata), the upgrade_type = security setting installs only packages that have a security advisory. Install the package with sudo dnf install dnf-automatic, then edit the relevant lines in /etc/dnf/automatic.conf as follows:

INI
# /etc/dnf/automatic.conf
[commands]
upgrade_type = security
download_updates = yes
apply_updates = yes

[emitters]
emit_via = stdio

Then enable the timer. dnf-automatic.timer follows the apply_updates value in the configuration file, while dnf-automatic-install.timer, which ships with the same package, installs updates regardless of that value. Enable only one of the two.

Bash
sudo systemctl enable --now dnf-automatic.timer
systemctl list-timers 'dnf-automatic*'
# Pending security updates
sudo dnf updateinfo list --security
# Output of recent runs
sudo journalctl -u dnf-automatic.service -n 50 --no-pager

With emit_via = stdio, the output of each run goes to the systemd journal. You can see the full list of installed packages with dnf history and dnf history info last.

Is a reboot needed, and how do you plan it?

Checking whether a reboot is required

On Ubuntu and Debian, installing a package that requires a reboot creates the file /var/run/reboot-required; the packages responsible are listed in reboot-required.pkgs. On Debian, this file is created for kernel updates by the script that the unattended-upgrades package places under /etc/kernel/postinst.d/. needrestart shows the services still using old libraries and whether the running kernel is current; it is usually installed on Ubuntu servers, and on Debian you can add it with sudo apt install needrestart. On AlmaLinux, dnf needs-restarting from the dnf-plugins-core package does the same check.

Bash
# Ubuntu / Debian
ls /var/run/reboot-required 2>/dev/null && cat /var/run/reboot-required.pkgs
sudo needrestart -r l
# AlmaLinux 9 (exit code 1: reboot required)
sudo dnf needs-restarting -r
sudo dnf needs-restarting -s
# Running kernel and installed kernels
uname -r
ls -1v /boot/vmlinuz-*

If the running kernel shown by uname -r is older than the newest installed kernel, the server is waiting for a reboot. dnf needs-restarting -r returns exit code 1 when a reboot is required and 0 when it is not, so you can also use it in monitoring scripts. If only services are affected, restarting the services in the list is usually enough instead of rebooting the whole server.

Steps for a planned reboot

  1. Pick your lowest-traffic hour and, if needed, notify your users in advance.
  2. Take a snapshot with the Snapshots tool in the client area. A snapshot freezes the disk state of the running server at that moment; if your database is writing heavily, time it for a quiet period.
  3. Apply pending updates and schedule the reboot (commands below). You can cancel a reboot scheduled with shutdown -r 04:00 by running shutdown -c.
  4. Once the server is back up, check the new kernel, failed services, the error log and that VMware Tools is running.
  5. If everything is fine, delete the snapshot within a few days.
Bash
# Apply pending updates
sudo apt update && sudo apt upgrade      # Ubuntu / Debian
sudo dnf upgrade                         # AlmaLinux
# Reboot at 04:00 server time (cancel: sudo shutdown -c)
timedatectl
sudo shutdown -r 04:00
# Check after the server is back up
uname -r
systemctl --failed
sudo journalctl -b -p err --no-pager | tail -n 30
systemctl status open-vm-tools --no-pager   # Ubuntu / Debian
systemctl status vmtoolsd --no-pager        # AlmaLinux
Warning

The Snapshots tool keeps at most 2 snapshots at a time, and snapshots grow over time and affect performance. Delete the snapshot once your checks are complete; it also has to be deleted before a disk expansion. A snapshot is not a substitute for a full backup; see the snapshot guide for details.

If the server does not respond to SSH after the reboot, do not press Hard Reset right away. First look at the screen with the VNC Console: a file system check (fsck) may be running at boot, or the boot process may be stuck on an error. For the differences between power actions, read the power actions guide. If the new kernel causes problems, rolling back to the snapshot is the fastest way back.

Common problems

SymptomLikely causeFix
Could not get lock /var/lib/dpkg/lock-frontendAn automatic update is running in the backgroundWait for it to finish and watch it with systemctl status apt-daily-upgrade.service; do not delete the lock files
A conffile prompt warning in the log and a skipped packageA configuration file you changed was also changed in the package's new versionUpgrade by hand with sudo apt upgrade, review the difference and make your choice
deferred due to phasing (Ubuntu)A phased update: the update is being rolled out to users graduallyThis is normal; the package arrives on its own within a few days
Docker or other third-party packages are not updatedThe source is not in the list of allowed repositoriesUpdate them by hand, or add the source to the list deliberately
dnf-automatic installed nothingNo pending security advisories, or the timer is not enabledCheck the output of dnf updateinfo list --security and systemctl list-timers 'dnf-automatic*'
A service did not start after the rebootA configuration incompatibility with the new versionInvestigate with systemctl --failed and journalctl -u service-name -b; roll back to the snapshot if needed

End-of-life releases and the application layer

Automatic updates only help if the distribution still publishes updates. Check your release with cat /etc/os-release. Standard support has ended for CentOS 7 and 8, CentOS Stream 8, Ubuntu 18.04 and 20.04, and Debian 10; these systems no longer receive security updates from the regular repositories and remain in the template list only for compatibility with older applications. Ubuntu's interim releases (for example, 24.10 and 25.04) are supported for only nine months, so their support has ended too. For new installations, choose Ubuntu 24.04 or 26.04 LTS, Debian 12 or 13, or AlmaLinux 9.

Upgrading an end-of-life system in place across several releases is risky. In most cases the cleanest route is to move your data off the server and use the Reinstall OS tool with a supported release; this erases all data on the disk. For the preparation steps, see the reinstallation guide.

Operating system updates do not cover the applications running on top of it. WordPress core, plugins and themes are updated through their own mechanisms (WordPress security guide). Control panels and dependencies installed with Composer or npm are also updated with their own tools. Docker containers keep running old software until the image is refreshed and the container is recreated:

Bash
cat /etc/os-release
# In a Docker Compose project, pull new images and recreate the containers
cd /opt/app
docker compose pull && docker compose up -d
docker image prune

For details, see the Docker guide; for Windows servers, see the Windows Server maintenance guide.

Frequently asked questions

Can automatic updates break my server?

The risk is low but not zero. Security updates are small patches to the installed release, and package maintainers take care to preserve compatibility. The updated package's service is usually restarted, and occasionally a configuration incompatibility can surface. Manage this risk with regular off-site backups, snapshots before significant changes and by watching the logs; turning updates off is a much bigger risk.

Are release upgrades (for example, 24.04 to 26.04) automatic too?

No. unattended-upgrades and dnf-automatic only update the packages of the installed release. On Ubuntu, a release upgrade is done by hand with do-release-upgrade; on Debian, by switching the repository definitions to the new codename. On AlmaLinux, an in-place move to the next major version requires a separate upgrade tool. Do this work in a maintenance window after taking a snapshot and a backup, or choose a clean install instead.

Was this helpful?

Thanks for your feedback!

Still Need Help?

Our support team is here around the clock for anything you can't find above.