unattended-upgrades: Let Your Server Patch Itself While You Sleep (Safely)
The most dangerous patch is the one waiting for you to have a free afternoon. unattended-upgrades installs security fixes on its own. Here's how to check it's on, what it touches, and how to stop it rebooting your database at dinner.
Silas Voss
3 min read
There is a patch on your server's to-do list right now. It's been there since Tuesday. It's waiting for you to have a free afternoon.
You will not have a free afternoon. Nobody has had a free afternoon since 2019.
unattended-upgrades is the tool that stops waiting for you. It installs security updates on its own, quietly, every day. On Ubuntu it's usually installed and switched on already, which means it may have been saving you for years without a thank-you card. Today we check that it's working, decide what it may touch, and stop it from rebooting things at dinner.
Is it actually on?
Two settings decide whether it runs. Look here:
cat /etc/apt/apt.conf.d/20auto-upgrades
You want to see:
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "1";
"1" means every day. If the file is missing, or says "0", it's off. Turn it on the official way:
sudo apt install unattended-upgrades
sudo dpkg-reconfigure -plow unattended-upgrades
Answer "Yes", and it writes that file for you.
The schedule itself comes from two systemd timers, apt-daily.timer (refresh the package lists) and apt-daily-upgrade.timer (install). If you read Tux's systemd timers post, you know the trick:
systemctl list-timers 'apt-daily*'
What is it allowed to touch?
The rules live in /etc/apt/apt.conf.d/50unattended-upgrades. The important part is the list of allowed origins. On Ubuntu, the defaults include a line like:
"${distro_id}:${distro_codename}-security";
That's the security pocket: fixes for known vulnerabilities, kept deliberately small and boring. Boring is the point. It's a different thing from "upgrade everything to the newest version whenever", which is how you wake up to a surprise PHP version.
To keep a package away from automatic updates entirely, list it:
Unattended-Upgrade::Package-Blacklist {
"postgresql-";
};
Entries are matched as patterns, so postgresql- covers the whole family. Use this sparingly. Every package on the list is one you've promised to patch by hand. Promise carefully.
Try it without consequences
Before trusting it, watch it think out loud:
sudo unattended-upgrade --dry-run --debug
It goes through what it would install and why, and changes nothing. If it says something you didn't expect, now is the time to find out, not after.
What it actually did ends up here:
less /var/log/unattended-upgrades/unattended-upgrades.log
Read it once a week, or better, have monitoring read it for you. "I assumed it was working" is a sentence I hear mostly at incident reviews.
Reboots: the part that bites
Kernel fixes need a reboot. unattended-upgrades can do that too, and you get to choose:
Unattended-Upgrade::Automatic-Reboot "false";
Unattended-Upgrade::Automatic-Reboot-Time "02:00";
false(the usual default): it patches, leaves/var/run/reboot-requiredbehind and waits for a human. Safe, but only as good as the human.true: it reboots at the time you set. Great for stateless web nodes behind a load balancer. Exciting for a lone database server. "Exciting" is not a word you want in an incident report.
Pick per server, not per mood. Two more settings worth turning on:
Unattended-Upgrade::Remove-Unused-Kernel-Packages "true";
Unattended-Upgrade::Mail "root";
The first stops old kernels from filling /boot until updates start failing. The second sends a report, provided the server can actually send mail. Check that, or you're mailing reports into the void. The void does not read them.
Restarting what it patched
Updating a library doesn't fix the processes that already loaded the old one. That's needrestart's job, and it works hand in hand with unattended-upgrades. See last week's post, "Patched Isn't Running", for setting that up.
What to do today
Automated patching isn't about trusting the machine. It's about not trusting your free afternoon.
Security
More like this
Security
Who Did That? Tracing sudo and Logins on a Linux Server
The config changed overnight and nobody did it. Everyone says so. The logs disagree. How to read sudo logs and login records, record whole sudo sessions, watch key files with auditd, and why the logs shouldn't only live on the box.
Security
What fail2ban Actually Stops (and the Things It Was Never Going To)
fail2ban is the bouncer who throws out anyone who gets their name wrong three times. Useful, and not a security strategy. How to set up its SSH jail, check who it has banned, and know what it can't protect you from.
Security
How to Read a CVE Without Panicking: CVSS, KEV and EPSS Explained
A 9.8 CVE drops on a Friday and your group chat catches fire. Before you cancel the weekend, learn how to read a CVE: what the score measures, what it doesn't, and the two lists that tell you whether anyone is actually attacking it.