Sub topic 12
Automating Updates with unattended-upgrades and dnf-automatic
Assume you can use sudo, read systemd timer status, and have a test Debian, Ubuntu, or RHEL-family server. Automation reduces the time that security fixes remain unapplied, but it does not remove the need for testing, monitoring, or reboot planning.
Choose a conservative policy
Automatic patching should have clear limits:
- Select trusted repositories only.
- Apply security updates automatically where practical.
- Record package transactions and keep logs.
- Avoid automatic major-release upgrades.
- Plan reboots separately unless the server is disposable.
- Test the policy on one non-production host first.
| Platform | Automatic update tool | Main control file | Typical scheduler |
|---|---|---|---|
| Debian or Ubuntu | `unattended-upgrades` | `/etc/apt/apt.conf.d/50unattended-upgrades` | `apt-daily-upgrade.timer` |
| RHEL-family | `dnf-automatic` | `/etc/dnf/automatic.conf` | `dnf-automatic.timer` |
The tools install routine package updates. They do not upgrade Debian or Ubuntu to a new release, and they do not move a RHEL-family system to a new major version.
Configure Debian and Ubuntu
Install the package and enable daily package-list refreshes and unattended upgrades:
sudo apt install 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";
EOF
sudo unattended-upgrade --dry-run --debug
systemctl status apt-daily-upgrade.timerThe value 1 means once per day. Review /etc/apt/apt.conf.d/50unattended-upgrades to confirm which repository origins are allowed. On many installations, the default policy includes security updates but excludes unrelated third-party repositories.
The dry run does not install packages. Use it after changing the policy to confirm the selected packages. Check logs in /var/log/unattended-upgrades/ and the APT history log.
Configure RHEL-family systems
Install dnf-automatic, edit its configuration, and select security updates:
sudo dnf install dnf-automatic
sudoedit /etc/dnf/automatic.confSet these values in the [commands] section:
[commands]
upgrade_type = security
apply_updates = yesStart the timer and inspect its next run:
sudo systemctl enable --now dnf-automatic.timer
systemctl status dnf-automatic.timer
systemctl list-timers dnf-automatic.timerThe security setting depends on security advisory metadata supplied by the configured repositories. Confirm that those repositories publish usable update information. Review the system journal and DNF transaction history after a run.
sudo journalctl -u dnf-automatic.service
sudo dnf history listTest, stage, and verify
Use a small rollout:
- Apply the policy to a test server.
- Confirm that only approved repositories and update classes are selected.
- Check application health, listening ports, scheduled jobs, and disk space.
- Apply the same policy to one production server.
- Compare monitoring results before expanding the rollout.
A staged policy separates package installation from reboot decisions:
Exercise
Exercise
A production server must receive security fixes automatically, but it must never reboot without an operator. Which settings and checks support that policy?
Show answer
Configure unattended-upgrades or dnf-automatic to apply approved security updates, leave automatic reboot disabled, enable the relevant systemd timer, review updater logs and transaction history, and monitor reboot-required indicators for a planned maintenance window.