Skip to content
System

Unattended upgrades on Debian: automating patches without losing control

Avatar illustré de Julien Macé 4 min read
Tux protège un serveur Debian pendant l’installation automatique de correctifs
Unattended-upgrades automatise les correctifs Debian tout en laissant les dépôts, les logs et les redémarrages sous contrôle.

Automating security patches on Debian prevents leaving a server exposed simply because an update was missed. But APT shouldn’t become a black box. With unattended upgradesYou can limit the allowed repositories, test the configuration, track each installation in the logs and keep reboots under control.

On a server, I gladly enable automatic security updates, but I leave automatic restart disabled until a maintenance window and monitoring are planned.

Tux protects a Debian server during the automatic installation of patches.
Unattended-upgrades automates Debian patches while keeping repositories, logs, and reboots under control.

Install and activate unattended upgrades

First, update the APT index, then install the package:

sudo apt update
sudo apt install unattended-upgrades

Debian provides a wizard to enable automatic updates. It creates or adjusts the periodic APT configuration:

sudo dpkg-reconfigure -plow unattended-upgrades

Accept activation only if you have verified that the server is using the correct repositories. A file sources.list Any repository containing an outdated mirror, an uncontrolled third-party repository, or an inconsistent Debian version must be fixed before automating anything. Debian version control commands.

Check the frequency actually applied by APT

The periodic configuration is usually found in /etc/apt/apt.conf.d/20auto-upgradesA minimal setting looks like this:

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

The value one It requires daily checking. Don’t just open the file: APT can combine multiple configuration fragments. Display the final view with:

apt-config dump | grep -i -E 'Periodic|Unattended'

On recent versions of Debian, the systemd units apt-daily.timer And apt-daily-upgrade.timer trigger the download and installation. Control them directly:

systemctl list-timers 'apt-daily*'
systemctl status apt-daily.timer apt-daily-upgrade.timer --no-pager
systemctl cat apt-daily-upgrade.timer

Timers can add a random delay. A time displayed in list-timers Therefore, the timing may differ from when you expected the treatment to start. If you need to review the difference between unit activation and startup, see the article Systemctl enable details these states.

Limit the number of authorized deposits

The main file is /etc/apt/apt.conf.d/50unattended-upgrades. The section Origins-Pattern Or Allowed-OriginsDepending on the package version, it decides which origins can be installed without intervention.

Make a backup before making any changes:

sudo cp /etc/apt/apt.conf.d/50unattended-upgrades /etc/apt/apt.conf.d/50unattended-upgrades.bak-$(date +%F-%H%M)
sudoedit /etc/apt/apt.conf.d/50unattended-upgrades

For a standard server, start with the provided Debian configuration and prioritize security patches. Do not automatically add all third-party repositories. An application repository might deliver a new major version, modify a configuration, or restart a business service.

If you only need to override a few options, create a separate local file. It will be easier to review after an upgrade.

sudoedit /etc/apt/apt.conf.d/52unattended-upgrades-local

Avoid copying the entire file 50 unattended upgrades in this override. Keep only the options that you assume locally, otherwise you will hide the enhancements provided by the Debian package.

Test without installing a package

A dry run is essential after changing the origin or option. It displays eligible packages without installing them:

sudo unattended-upgrade --dry-run --debug

Pay particular attention to the lines indicating allowed origins, retained packages, and exclusions. If the test selects an unexpected repository, return to the configuration before running the actual test.

To manually execute the process after validation:

sudo unattended-upgrade -v

Do not run this command while another apt Or dpkg works. If you encounter a lock or incomplete dependencies, do not randomly delete lock files. Check active processes, and then use the repair procedure described in the dpkg and apt guide.

Keep automatic restarts disabled

A kernel or critical library update may require a reboot. This does not mean that Debian should reboot the server without your consent. In the local file 52 unattended upgrades localimpose:

Unattended-Upgrade::Automatic-Reboot "false";

After installation, check if a restart is required:

test -f /var/run/reboot-required && cat /var/run/reboot-required
cat /var/run/reboot-required.pkgs 2>/dev/null || true

Next, schedule the reboot during a known window, using a backup console if the server is remote. The guide Systemctl reboot provides the checks to be done before and after the restart.

If your infrastructure already has high availability, monitoring, and a robust maintenance procedure, automatic restart can be considered. In this case, first test the behavior on a pilot machine and verify application dependencies. Enabling the option simply because a reboot time is configurable remains too risky on a business server.

Read the logs after each visit

Unattended-upgrades writes in his journals /var/log/unattended-upgrades/Check the last pass with:

sudo tail -n 100 /var/log/unattended-upgrades/unattended-upgrades.log
sudo tail -n 100 /var/log/unattended-upgrades/unattended-upgrades-dpkg.log
sudo journalctl -u unattended-upgrades.service -n 100 --no-pager

Check for installed packages, retained packages, dependency errors, and restarted services. To trace a file during manual testing, use tail liveFor an analysis per systemd unit, see the guide. journalctl allows for a narrowing of the timeframe and priority.

The Debian man page forunattended-upgrade details the debug mode and the dry run test. Debian Administrator’s Manual place this tool within a strategy of regular updates.

Once in place, maintain three controls in your monitoring: date of the last successful pass, APT errors, and presence of /var/run/reboot-requiredThis way you automate the fixes, not the loss of visibility.

Share Facebook X WhatsApp LinkedIn Pinterest Reddit Email