Unattended security updates and reboots on Ubuntu
Unattended-upgrades installs security updates automatically on a schedule and can reboot the server at a set time when a kernel or core library needs it.
- Updated Nov 27, 2026
- Markdown
Turn on automatic security updates, choose a reboot time, test the setup with a dry run and read the update logs.
- Ubuntu or Debian server with sudo
Security fixes are only useful once they are installed. On a server nobody logs into every day, the practical way to stay patched is unattended-upgrades: it checks daily, installs security updates, and can reboot the machine at a time you choose when the kernel or a core library changed. This lesson builds on keep a server updated.
How it works#
Two files in /etc/apt/apt.conf.d/ drive it:
20auto-upgradesis the on switch. It sets how often apt refreshes package lists and runs the unattended job, in days.50unattended-upgradessays what may be installed (the allowed origins, normally the security pocket of your release), which packages to skip, and what to do about reboots and mail.
A systemd timer (apt-daily and apt-daily-upgrade) runs the job daily. The run installs eligible updates and writes logs under /var/log/unattended-upgrades/. When a package needs a restart to take effect, it creates /var/run/reboot-required. Unattended-upgrades will leave the machine running with the old kernel until someone reboots, unless you turn on automatic reboot.
Step 1: Install and enable#
sudo apt update
sudo apt install unattended-upgrades
sudo dpkg-reconfigure -plow unattended-upgradesThe dialog asks if stable updates should be installed automatically. Answer Yes. This writes /etc/apt/apt.conf.d/20auto-upgrades:
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "1";Each 1 means once a day. Many Ubuntu server images already ship with this on, so look at the file before changing it.
Step 2: Review what is allowed#
Open the main file:
sudo nano /etc/apt/apt.conf.d/50unattended-upgradesFind Unattended-Upgrade::Allowed-Origins. The security line is enabled by default and ordinary update lines are commented out with //. Keep it that way if you want the lowest risk: security fixes only, no surprise feature upgrades. If you run a service that must not restart unexpectedly, add its package to Unattended-Upgrade::Package-Blacklist and update it by hand.
Docker or other third-party repositories are not included unless you add their origin. That is usually what you want, since you should update containers deliberately. See update a container to a new image.
Step 3: Decide on automatic reboot#
Without a reboot, a kernel fix is installed but not running. Two lines in the same file control this:
Unattended-Upgrade::Automatic-Reboot "true";
Unattended-Upgrade::Automatic-Reboot-Time "04:00";The server will reboot at 04:00 server time, only when /var/run/reboot-required exists. Choose your quietest time. Before enabling, confirm every service comes back by itself: systemd units are enabled and containers have a restart policy, so a reboot does not leave you down. If you cannot accept any downtime, leave it off and reboot by hand in a window, using monitoring to notice a failed start.
There is also Unattended-Upgrade::Automatic-Reboot-WithUsers, which controls whether it reboots when someone is logged in. Read the comment above it in the file.
Step 4: Dry run and force a run#
sudo unattended-upgrade --dry-run --debugThis prints the allowed origins, the packages it would upgrade and the ones it skips, without changing anything. To run it for real now rather than wait for the timer:
sudo unattended-upgrade -dCheck that the timers are active too:
systemctl list-timers 'apt-daily*'Step 5: Read the logs#
ls /var/log/unattended-upgrades/
sudo less /var/log/unattended-upgrades/unattended-upgrades.logLook for lines such as Packages that will be upgraded: and All upgrades installed. The -dpkg.log file holds the package manager output, which is what you need when an upgrade fails. Make a habit of reading it after the first week.
Check it worked#
cat /etc/apt/apt.conf.d/20auto-upgrades
systemctl list-timers 'apt-daily*'
sudo unattended-upgrade --dry-run --debug
ls /var/run/reboot-required 2>/dev/null && cat /var/run/reboot-required.pkgsThe timers should show a next run time. If the reboot flag exists, the .pkgs file names the packages that caused it. To see which kernel is running, use uname -r. For a wider system review see audit a Linux server.
Edge cases and gotchas#
- Held by a lock. If another apt process runs, the job can fail with a lock error. It retries on the next run.
- Services restart. Updating a library can restart services that use it, which is a brief interruption. Use
needrestartoutput in the log to see what was restarted. - Kernel not running. Security fixed in the installed kernel does nothing until the reboot. A long uptime with a pending flag means you are exposed.
- Time zone. Automatic-Reboot-Time uses the server’s local time zone, which is often UTC. Check with
timedatectl. - Release upgrades. Unattended-upgrades does not move you to a new Ubuntu release. That is a separate, manual job.
- Containers are not covered. Packages inside images are not updated by the host. Rebuild images regularly and scan them.
Troubleshooting#
| Symptom | Likely cause | Fix |
|---|---|---|
E: Could not get lock /var/lib/dpkg/lock-frontend | Another apt run holds the lock | Wait for it to finish, then retry |
| No log files appear | Unattended run is not enabled | Check 20auto-upgrades and the timers |
No packages found that can be upgraded unattended | Nothing eligible, or origins too narrow | Normal if up to date, otherwise review Allowed-Origins |
| Reboot did not happen | Automatic-Reboot is false or no flag file | Check the setting and /var/run/reboot-required |
| Server rebooted at a bad time | Time zone differs from expectation | Check timedatectl, change the time |
dpkg was interrupted, you must manually run 'dpkg --configure -a' | A run was cut off | Run sudo dpkg --configure -a |
| Updates held back | Package in blacklist or phased update | Read the --dry-run --debug output |
Quick reference#
sudo apt install unattended-upgrades
sudo dpkg-reconfigure -plow unattended-upgrades
cat /etc/apt/apt.conf.d/20auto-upgrades
sudo nano /etc/apt/apt.conf.d/50unattended-upgrades
sudo unattended-upgrade --dry-run --debug
ls /var/run/reboot-required
ls /var/log/unattended-upgrades/Related lessons#
- Keep a server updated: manual updates with apt.
- Package management with apt: how apt sources and holds work.
- Docker restart policies: make containers survive a reboot.
- Scan Docker images with Trivy: patch the software inside containers too.
- Audit a Linux server: confirm the server state after updates.
Next#
Continue with Manage secrets on servers and containers.
Check what you learned
Frequently asked questions
Is it safe to enable unattended-upgrades?
By default it installs only security updates from the official security origin, which is the low-risk choice. Services may restart during an update, so watch the first few runs on a server with important workloads.
How do I know if my server needs a reboot?
Check whether /var/run/reboot-required exists. Kernel and core library updates create it, and the file /var/run/reboot-required.pkgs lists the packages that caused it.
Where are unattended-upgrades logs?
In /var/log/unattended-upgrades/. The file unattended-upgrades.log lists what was installed, and unattended-upgrades-dpkg.log has the package manager output.
How do I test unattended-upgrades without installing anything?
Run sudo unattended-upgrade --dry-run --debug. It shows which packages would be upgraded and why others were held back.
Sources
Keep going: guides and tutorials
- Manage Secrets Self-Hosted: Env Vars and Master Key Rotation Set env vars and encrypted secrets on a self-hosted server, apply changes safely, and rotate the master key with no downtime without locking yourself out.
- Install a Self-Hosted PaaS on Your Own Server in Five Minutes One installer download, one setup token, one sample app. The full Levelrail install on a fresh Linux server, with the checks and the fixes.