Log inSign up

Keep a server patched without logging in every day

On Ubuntu and Debian install unattended-upgrades, enable it with sudo dpkg-reconfigure -plow unattended-upgrades and set a reboot time in /etc/apt/apt.conf.d/50unattended-upgrades. On Rocky Linux 9 and AlmaLinux 9 install dnf-automatic, set upgrade_type = security and apply_updates = yes, then enable dnf-automatic.timer. Security fixes then land daily, and a dry run plus the logs prove it works.

Topic: Server basics · Tested on: Ubuntu 24.04 and 22.04, Debian 12 and 13, Rocky Linux 9, AlmaLinux 9 · Updated 2026-12-03

Why automate security updates on a VPS?

Automating patches closes known holes within a day instead of whenever you next remember to log in. A server with a public IPv4 and IPv6 address is scanned constantly, and most successful break-ins use flaws that already had a fix published. Small projects suffer most here: a bot, a personal site or a node that runs for months untouched slowly falls behind.

Automatic updates are not a replacement for planned maintenance. Major release upgrades, new kernels that change behaviour and application stacks pinned to exact versions still need a human. The goal of this guide is a narrow, safe policy: security fixes install themselves, everything else waits for you, and reboots happen at a time you pick. Pair it with the daily backups add-on or restic so a bad package can always be rolled back by restoring data.

How do I enable unattended-upgrades on Ubuntu and Debian?

Install the package (Ubuntu images already carry it, some Debian builds do not) and switch on the daily run:

sudo apt update
sudo apt install unattended-upgrades apt-listchanges
sudo dpkg-reconfigure -plow unattended-upgrades
cat /etc/apt/apt.conf.d/20auto-upgrades

The reconfigure step writes two lines into 20auto-upgrades:

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

The value is an interval in days. Two systemd timers drive the work: apt-daily.timer refreshes package lists and apt-daily-upgrade.timer installs updates, each with a random delay so thousands of machines do not hit the mirrors at once. Check them with:

systemctl list-timers "apt-daily*"

Which updates does it install by default?

Out of the box only the security pocket is allowed. Open /etc/apt/apt.conf.d/50unattended-upgrades and look at the origins block. On Ubuntu it contains lines such as "${distro_id}:${distro_codename}-security"; plus the ESM entries, and the -updates line is commented out. Debian uses Unattended-Upgrade::Origins-Pattern with label=Debian-Security.

Leave that as it is for a production server. If you want all stable updates on a hobby box, remove the // in front of the updates line. To hold back one package, for example a database you upgrade by hand, add it to the blacklist section:

Unattended-Upgrade::Package-Blacklist {
    "postgresql-16";
};

Entries are regular expressions, so "linux-"; would pause every kernel package.

How do I set a reboot policy?

Decide whether the server may reboot itself; kernel and libc fixes only take effect after a restart. In the same 50unattended-upgrades file, uncomment and adjust:

Unattended-Upgrade::Remove-Unused-Kernel-Packages "true";
Unattended-Upgrade::Remove-Unused-Dependencies "true";
Unattended-Upgrade::Automatic-Reboot "true";
Unattended-Upgrade::Automatic-Reboot-WithUsers "false";
Unattended-Upgrade::Automatic-Reboot-Time "04:10";

With these settings the machine reboots at 04:10 server time only when a package created /var/run/reboot-required, and skips the reboot while someone is logged in. Check the server clock and zone first (see time zone and time sync). If a reboot would hurt, for example a Bitcoin node in the middle of initial sync, keep Automatic-Reboot at false and read the flag yourself:

cat /var/run/reboot-required.pkgs 2>/dev/null || echo "no reboot needed"

What does needrestart do after an update?

needrestart finds running daemons that still use an old copy of an updated library and restarts them, so a patched OpenSSL is really in use without a full reboot. Ubuntu 22.04 and 24.04 include it; on Debian install it with sudo apt install needrestart. It runs automatically after every apt transaction.

The restart mode lives in /etc/needrestart/needrestart.conf or a drop-in file under /etc/needrestart/conf.d/. The letter i asks interactively, l only lists, and a restarts without asking. For unattended servers set automatic mode in a drop-in:

echo "\$nrconf{restart} = 'a';" | sudo tee /etc/needrestart/conf.d/50-auto.conf
sudo needrestart -r l
sudo needrestart -k

The -k check reports whether the running kernel is older than the newest installed one. Services that must never bounce can be excluded with $nrconf{override_rc} entries in the same drop-in.

How do I set up dnf-automatic on Rocky Linux and AlmaLinux?

Install dnf-automatic, edit one file and enable the timer. Rocky Linux 9 and AlmaLinux 9 both publish security advisories in their repository metadata, so a security-only policy works as expected:

sudo dnf install dnf-automatic
sudo vi /etc/dnf/automatic.conf

In the [commands] section set:

upgrade_type = security
download_updates = yes
apply_updates = yes

Then start the timer and look at what is pending:

sudo systemctl enable --now dnf-automatic.timer
systemctl list-timers dnf-automatic.timer
sudo dnf updateinfo list --security

The [emitters] section can write results to the journal (emit_via = stdio) or send mail. Recent dnf builds also accept a reboot = when-needed option; run man dnf-automatic to see whether your version has it. If not, schedule a check with sudo dnf needs-restarting -r, which exits with code 1 when a reboot is required.

How do I test that updates really run?

Run each tool by hand once and read the logs. On Ubuntu and Debian a dry run shows which packages would be chosen and why:

sudo unattended-upgrade --dry-run --debug
sudo tail -n 50 /var/log/unattended-upgrades/unattended-upgrades.log
grep -h " install " /var/log/dpkg.log | tail

On Rocky and Alma start the service directly and follow its journal:

sudo systemctl start dnf-automatic.service
journalctl -u dnf-automatic.service -n 40
sudo dnf history list | head

A day later, check again that the timer fired on its own. An empty log after several days usually means the timer is disabled or the origins pattern matches nothing.

What can go wrong and how do I fix it?

Most failures come from a locked package database, a full disk or a held package. If unattended-upgrades reports that dpkg was interrupted, finish the previous run:

sudo dpkg --configure -a
sudo apt -f install

When /boot or the root disk is full, old kernels pile up; free space with sudo apt autoremove --purge or, on Rocky and Alma, lower installonly_limit in /etc/dnf/dnf.conf. The disk usage guide shows how to find the rest. If an update broke a service, look at journalctl -u name -b, downgrade the one package with apt install package=version or dnf downgrade package, and add it to the blacklist or the exclude= line until a fixed build arrives. Because there is no browser console on our servers, keep at least one way back in: test SSH after every kernel reboot, and keep the console Restart action in mind if a boot hangs.

Plans that fit this guide

Base city prices. Every plan includes a dedicated IPv4 address, IPv6, full root and all 18 images.

All prices
PlanFits becauseSizeMonthlyOrder from
A1-1updates run fine on the smallest size1 vCPU, 1 GB RAM, 25 GB NVMe$3.60/mo$43.20 for 12 months
A1-2more headroom while packages unpack1 vCPU, 2 GB RAM, 50 GB NVMe$7.20/mo$43.20 for 6 months

Questions about Automatic security updates

Will automatic updates break my applications?

Security updates within a stable release are built to be compatible, so breakage is rare. Restricting the policy to security fixes, holding back the packages your app depends on and keeping backups covers most of the remaining risk.

Should the server reboot itself?

For web servers and bots a short nightly reboot window is usually fine and keeps the kernel current. For long running jobs, nodes or game servers, leave automatic reboots off and plan them yourself with the reboot guide.

How do I get a mail when updates install?

Set Unattended-Upgrade::Mail on Debian or Ubuntu, or emit_via = email in dnf-automatic. Outgoing mail needs a working relay; port 25 may not be open, so use an authenticated SMTP relay on port 587 or ask support by ticket first.

Does this also update Docker images or language packages?

No. It only covers system packages from apt or dnf. Containers, pip, npm and Composer packages need their own update routine.

How do I check the last time updates ran?

Read /var/log/unattended-upgrades/unattended-upgrades.log on Ubuntu and Debian, or run sudo dnf history list and journalctl -u dnf-automatic on Rocky and Alma.

Is FreeBSD covered?

Not by these tools. FreeBSD uses freebsd-update for the base system and pkg upgrade for packages; see the FreeBSD upgrade guide.