Qvantor logo QvantorInfrastructure, explained plainly
Guides

Unattended Upgrades on Ubuntu for Automatic Security Patches

Your small Ubuntu server has been running quietly for months, and you cannot remember the last time you ran apt upgrade.

Small home server on a shelf next to a laptop showing a terminal with package update logs scrolling

Your small Ubuntu server has been running quietly for months, and you cannot remember the last time you ran apt upgrade. Meanwhile a patched OpenSSH or OpenSSL release has been sitting in the archive for weeks, and your box is still on the old version. Setting up unattended upgrades on Ubuntu fixes that gap in about fifteen minutes, as long as you configure it to patch security updates only, tell it when it may reboot, and make it report back to you.

This walkthrough targets Ubuntu 22.04 and 24.04 LTS on a single VPS or home server. The same files exist on Debian 12 with slightly different origin names.

What unattended upgrades on Ubuntu actually does

The unattended-upgrades package is a small Python script that apt runs on a timer. Twice a day, systemd fires apt-daily.timer to refresh package lists, and once a day apt-daily-upgrade.timer runs the upgrade step. The script reads an allow list of archive origins, installs any pending packages from those origins, and writes a log. Nothing outside the allow list is touched.

On a fresh Ubuntu cloud image the package is usually already installed and enabled with the security origin only. On minimal installs and some provider images it is missing. Check before you assume:

  • Installed? Run dpkg -l unattended-upgrades. A line starting with "ii" means yes.
  • Enabled? Run cat /etc/apt/apt.conf.d/20auto-upgrades and look for two lines set to "1".
  • Timers active? Run systemctl list-timers apt-daily* and confirm both timers show a next run time.

Step by step setup in five commands

If any of those checks failed, this is the full setup. Run everything as a user with sudo.

  1. Install the packages: sudo apt update then sudo apt install unattended-upgrades apt-listchanges.
  2. Enable the timers: sudo dpkg-reconfigure -plow unattended-upgrades and answer Yes. This writes 20auto-upgrades with Update-Package-Lists and Unattended-Upgrade both set to "1".
  3. Open the main config: sudo nano /etc/apt/apt.conf.d/50unattended-upgrades.
  4. Edit the origins, reboot and mail settings described in the next sections.
  5. Test with a dry run: run sudo unattended-upgrade with the dry-run and debug options added. Read the output for the line "Allowed origins are" and check it lists what you expect.

The dry run takes 20 to 60 seconds on a small VPS. If it prints "No packages found that can be upgraded unattended", that is not an error. It simply means you are already current.

Choosing which origins to allow

Inside 50unattended-upgrades you will see a block called Unattended-Upgrade::Allowed-Origins. On Ubuntu the defaults include lines for "${distro_id}:${distro_codename}-security" plus the ESM lines for Ubuntu Pro. Leave the security line uncommented. Leave the "-updates" line commented unless you have a reason to change it, which is covered in the counter-take below.

If you installed software from a third party repository such as Docker's apt repo, it is not included by default. That is deliberate. A Docker engine upgrade restarts the daemon and every container with it, and you want to choose when that happens.

Blocking packages you never want touched

The Unattended-Upgrade::Package-Blacklist block takes package names or regular expressions. Two common entries on small servers are a pinned database version, such as "postgresql-16", and kernel packages on a machine where you manage reboots by hand, written as "linux-". A blacklisted package still shows up when you list upgradable packages with apt, so you will not forget it exists.

Reboots, mail and the settings people skip

Patching a kernel or glibc does nothing until the service or machine restarts. Ubuntu writes /var/run/reboot-required when that happens, and unattended upgrades can act on it. These are the four lines worth uncommenting and setting:

SettingSuggested valueWhy
Automatic-Reboot"true"Kernel fixes take effect without you logging in
Automatic-Reboot-Time"04:30"Pick your quietest hour in server local time
Mail"you@yourdomain"A report after each run that changed something
MailReport"on-change"Avoids a daily email that says nothing happened

Mail only works if the server can send mail. On a box with no MTA, install a lightweight relay such as msmtp-mta and point it at a transactional mail account. If your server sends its own mail directly, make sure reverse DNS is right first, because reports from a host without a valid PTR record for the mail server often land in spam where nobody reads them.

Also set Remove-Unused-Kernel-Packages and Remove-Unused-Dependencies to "true". A 10 GB VPS boot partition fills up after six or seven kernel updates, and a full /boot is one of the few ways unattended upgrades can leave a server unbootable.

Why you should not enable every update automatically

A lot of guides tell you to uncomment the "-updates" origin so everything stays fresh. For a small server you run alone, I disagree. Security updates on Ubuntu LTS are narrow backported fixes with a low regression rate. The "-updates" pocket includes bug fix releases and behaviour changes, such as a new minor version of a language runtime or a revised default in a system service. Those are exactly the changes that break a working setup at 4:30 in the morning, and you find out from your users rather than from a mail report.

The better pattern is security patches automatic, everything else manual. Once a month, put 20 minutes in your calendar, take a snapshot or confirm last night's restic backup of the self hosted server finished, run apt full-upgrade, and watch the services come back. You get the safety of fast security fixes and you stay in control of change.

The same reasoning applies to automatic reboots on servers with no redundancy. If a reboot takes your only mail server offline for 90 seconds, that is fine. If your database needs a manual passphrase after a restart, it is not, and you should leave Automatic-Reboot off and reboot by hand.

Checking that it really ran

Set it and forget it is how servers end up two years behind. Spend two minutes a week on this for the first month, then once a month after that.

  • Read the log: less /var/log/unattended-upgrades/unattended-upgrades.log shows each run, which packages were installed, and any errors.
  • Check dpkg history: grep " install \| upgrade " /var/log/dpkg.log confirms what changed and when.
  • Look for a pending reboot: ls /var/run/reboot-required. If it exists for more than a day with automatic reboots on, something is wrong with the reboot time setting.
  • Watch from outside: an external monitor catches the one failure the logs cannot, which is a reboot that never came back. A free check from uptime monitoring with Uptime Kuma on a second machine covers this.

The most common error in the log is a dpkg lock held by another process, usually because you were running apt by hand at the same time. It resolves itself on the next run. A repeated "conffile prompt" error means a package wants you to choose between your edited config and the new default. Run apt upgrade manually once to answer it.

Frequently asked questions

Are unattended upgrades safe on a production server?

For security updates only, yes, on Ubuntu LTS the regression rate is low and the risk of staying unpatched is higher. Keep "-updates" and third party repositories out of the allow list, and pair it with backups and external monitoring. That combination is what most small teams run in practice.

How do I know if unattended upgrades is working?

Check /var/log/unattended-upgrades/unattended-upgrades.log for recent dated entries and run systemctl list-timers apt-daily* to see the next scheduled run. If you set Mail and MailReport, you will also receive an email after any run that installed packages.

Does unattended-upgrades restart services after updating?

On Ubuntu 22.04 and later, needrestart runs after package installs and restarts most affected services automatically in unattended mode. The kernel and a few core libraries still need a full reboot, which is what the Automatic-Reboot setting handles.

IV
Ilkka Varis

Ilkka has run mail servers for small companies since the days of hand edited DNS zones.

More posts by Ilkka

More in Guides

01doorganico 084goad 3hot8 4465456 after5internprogram ahandfulofblessings ahmadpc ahomcybersecurity allodialresources annodex antiquesandperiodcollectibles aotc asianworldkashmir beedlectrics bloggertemplatefree bluefeatheragency bodyweightsolution campaign08blog carfixadvisor catstreetcollective cbstvsports cnfanspurchasing committeeof500yearsofdignityandresistance covertopsdjs cs-kaiyuangame cuestacomunicaciontotal cxoutlet dancebetgame deskgearhub destinyvillastay detectmagazine di33 diamondsteelbuildings donmo dyanadropship emarsysfinance emimattl escapechan eskitarih evautoplay everythingweddings-orlando farmzone feedviewerapp foxstudiosscratch gamevui123 gleasongrade greetingsday hacklabasu haskell iw-kaiyun jagoanproperti jilidskripsi joltbusinessfinance juegodepokergratis juegospucca kaeru-festival latestmehndidesigns lestanzediottaviano litemagazines localcommunityhero lustrsazan mariashebets menswheels newwebstechs1 nikkit ootheday oxigenvpn plurfitness prefetial probudgetcarpetcleaning psychicmrsmartin pyaten rejoignezlogis rexzbot riselayouts ruchin rwxqsgd5 sakaltime shibiaowang shop-bot skrtips spotlesshaven strcoding tetapatrium topselller uneplanteartificielle vipertechcr webtech1223411 wo-kygaming yamaha-mekar yeknava yoybuysheets zenunwa yamaha-mekar jilidskripsi ankertoto ankertoto ankertoto