Sub topic 14
Turn on Automatic Security Updates
Prerequisites and update policy
This chapter assumes you can use sudo, identify whether the server is Debian-based or RHEL-based, and inspect systemd services and timers. A systemd timer is a scheduled unit that starts another service at a defined time.
Automatic updates reduce the time between a security fix being published and installed. They also introduce change without a manual review. Decide what the server may update automatically before enabling the feature.
| Policy | Benefit | Risk |
|---|---|---|
| Security updates only | Limits unexpected changes | Some dependent packages may remain outdated |
| All updates | Keeps the system broadly current | A new version may change behavior |
| Download only | Allows review before installation | Fixes are not applied automatically |
For many internet-facing servers, automatic security updates are a reasonable baseline. Test the policy on a similar system first.
Debian and Ubuntu
Install the unattended-upgrades package:
sudo apt update
sudo apt install unattended-upgradesEnable daily package-list downloads and unattended upgrades:
sudo tee /etc/apt/apt.conf.d/20auto-upgrades >/dev/null <<'EOF'
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "1";
EOFThe main policy file is /etc/apt/apt.conf.d/50unattended-upgrades. Review it rather than replacing it. Confirm that the allowed origins include your distribution's security repository. You can inspect the effective configuration with:
apt-config dump | grep -E 'APT::Periodic|Unattended-Upgrade'
systemctl list-timers apt-daily.timer apt-daily-upgrade.timerCheck update activity in the journal and package log:
journalctl -u apt-daily-upgrade.service
sudo less /var/log/unattended-upgrades/unattended-upgrades.logRHEL-family systems
Install and configure dnf-automatic:
sudo dnf install dnf-automatic
sudoedit /etc/dnf/automatic.confSet these options in the [commands] section:
upgrade_type = security
download_updates = yes
apply_updates = yesStart the timer and enable it at boot:
sudo systemctl enable --now dnf-automatic.timer
systemctl list-timers dnf-automatic.timer
journalctl -u dnf-automatic.serviceThe security setting depends on security advisories published by the repositories. If the repository does not provide usable advisory metadata, security-only selection may not behave as expected.
Reboots and operational checks
Some updates replace the running kernel or core libraries. The package update can succeed while the new code waits for a reboot. Plan reboots separately during a maintenance window. On Debian-based systems, check:
test -f /var/run/reboot-required && echo "Reboot required"Use monitoring to alert on failed timers, low disk space, and pending reboots. Automatic updates should be observable and reversible through package history or a system snapshot.
> callout warning > Do not enable automatic updates and assume the server is maintained. Check timer results, logs, repository reachability, and pending reboots regularly.
Exercise
Which command shows whether the Debian or Ubuntu automatic upgrade timer is scheduled?
Show answer
systemctl list-timers apt-daily-upgrade.timer