Unattended Upgrades on Ubuntu: Automatic Security Updates

· 0x.cloud Team

Unattended Upgrades on Ubuntu: Automatic Security Updates

The unattended-upgrades package on Ubuntu downloads and installs security updates by itself once a day. Ubuntu Server ships it enabled, but verify it: both settings in /etc/apt/apt.conf.d/20auto-upgrades should be "1", and sudo unattended-upgrade -v --dry-run should list the security origins. That way patches for OpenSSL, OpenSSH or the kernel land on your server without you logging in.

This guide covers enabling it, reboots, exclusions, logs, the "could not get lock" error and how to turn it off. Commands follow the Ubuntu Server docs for 24.04 LTS, with a Debian 12 section.

Check that automatic updates are on

apt list --installed 2>/dev/null | grep unattended-upgrades
cat /etc/apt/apt.conf.d/20auto-upgrades

Expected:

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

"1" means daily. systemd timers do the actual work:

systemctl list-timers 'apt-daily*'

apt-daily.timer refreshes package lists, apt-daily-upgrade.timer installs updates.

How to enable unattended upgrades on Ubuntu 24.04

If the package or 20auto-upgrades is missing:

sudo apt update
sudo apt install unattended-upgrades
sudo dpkg-reconfigure -plow unattended-upgrades   # answer Yes; writes 20auto-upgrades

Preview what would be installed, without changing anything:

sudo unattended-upgrade -v --dry-run

What gets updated: Allowed-Origins

Sources live in /etc/apt/apt.conf.d/50unattended-upgrades. Ubuntu's default is security only:

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";
};

-updates stays commented out. That's a sensible server default: security fixes go in automatically, and regular updates happen when you choose, as described in how to update an Ubuntu server.

Common trap: third-party repos aren't covered. Docker from download.docker.com, Node.js from NodeSource and PPAs aren't in Allowed-Origins, so unattended-upgrades skips them. Update them by hand or add their Origin to the list (you'll find the Origin field in the repo's InRelease file under /var/lib/apt/lists/).

Reboots, cleanup and exclusions

Keep your changes in a separate file that loads after the stock one, so package upgrades never ask about a modified config:

sudo tee /etc/apt/apt.conf.d/52unattended-upgrades-local > /dev/null <<'EOF'
// reboot at 04:00 server time if a kernel update requires it
Unattended-Upgrade::Automatic-Reboot "true";
Unattended-Upgrade::Automatic-Reboot-Time "04:00";
// remove dependencies that are no longer needed
Unattended-Upgrade::Remove-Unused-Dependencies "true";
// never touch these packages
Unattended-Upgrade::Package-Blacklist {
    "postgresql-";
};
EOF
Option Default When to change it
Automatic-Reboot false turn on if a minute of night downtime is fine (bot, n8n)
Automatic-Reboot-Time now pick a quiet hour in the server's timezone
Automatic-Reboot-WithUsers true false to skip reboots while someone is logged in
Package-Blacklist empty databases or anything you upgrade by hand

Run --dry-run again to confirm. Without auto-reboot, watch for /var/run/reboot-required after kernel updates.

Unattended-upgrades log

sudo tail -n 50 /var/log/unattended-upgrades/unattended-upgrades.log
sudo less /var/log/unattended-upgrades/unattended-upgrades-dpkg.log

The first file lists installed packages and errors; the second holds full dpkg output.

Stuck: Could not get lock

Right after a new server boots, apt install often fails with Could not get lock /var/lib/dpkg/lock-frontend. That's unattended-upgrades applying the first batch of patches. Check and wait a few minutes:

ps aux | grep -i unattended

Don't delete lock files or kill the process mid-install; that can leave dpkg half-configured. If it truly hangs for more than 30 minutes, read the log above.

How to disable automatic updates

sudo dpkg-reconfigure unattended-upgrades   # answer No

Or set both values in 20auto-upgrades to "0". To stop the timers entirely: sudo systemctl disable --now apt-daily.timer apt-daily-upgrade.timer. Only do this if you patch manually on a schedule.

Debian 12

A minimal Debian install may not have the package. Check with apt list --installed | grep unattended and install it if needed:

sudo apt install unattended-upgrades apt-listchanges
sudo dpkg-reconfigure -plow unattended-upgrades

Debian uses Unattended-Upgrade::Origins-Pattern in the same 50unattended-upgrades file. By default it installs security updates (label=Debian-Security) and stable point-release fixes (label=Debian, for example 12.12 to 12.13), while -updates stays commented out. Note that since July 11, 2026, Debian 12 security fixes come from the Debian LTS team (through June 30, 2028); they arrive through the same bookworm-security suite, so nothing needs to change.

Updates plus a safety net

Auto-updates close known holes but don't replace a UFW firewall, key-only SSH and a short list of open ports.

If you're setting up a fresh server to practice this, an s1-1 plan (1 vCPU, 1 GB RAM, 15 GB NVMe) at $4.49/month is plenty: unattended-upgrades needs almost no resources. With hourly billing a one-hour test costs about $0.030750, and setup is $0. Delete it and the unused balance goes back to your account. Plans are on the pricing page.

Before a big manual upgrade, take a snapshot ($0.99/month on 0x.cloud) so you can roll back in minutes. Or let an agent configure everything:

Prompt for an AI agent

Connect to my 0x.cloud server (with the MCP run_command tool or over SSH). Check that unattended-upgrades is installed and what /etc/apt/apt.conf.d/20auto-upgrades says; enable it if it's off. Create /etc/apt/apt.conf.d/52unattended-upgrades-local with automatic reboot at 04:00 server time, run unattended-upgrade -v --dry-run and show me the result.

FAQ

Is unattended-upgrades enabled by default on Ubuntu? On Ubuntu Server the package is installed by default and applies security updates once a day. Confirm that both lines in /etc/apt/apt.conf.d/20auto-upgrades are set to "1".

Does unattended-upgrades reboot the server? Not by default: Automatic-Reboot is false. When an update needs a reboot, /var/run/reboot-required appears. You can enable automatic reboots at a set time.

How do I disable unattended upgrades on Ubuntu? Set both values in /etc/apt/apt.conf.d/20auto-upgrades to "0", or run sudo dpkg-reconfigure unattended-upgrades and answer No. Only do this if you patch manually on a schedule.

What if an update breaks my server? Roll back to a snapshot ($0.99/month on 0x.cloud) or reinstall the OS for $0.