Automatic security updates on RHEL, Rocky Linux and AlmaLinux with dnf-automatic
dnf-automatic installs package updates from a systemd timer. With upgrade_type = security it installs only
the updates that come with a security advisory. The setup was tested on Rocky Linux 9.9 and 10.3, which use
dnf 4 and the same dnf-automatic package as RHEL and AlmaLinux, and on Rocky Linux 8.10 (dnf 4.7), which lacks
the reboot setting.
Install
sudo dnf install dnf-automatic
Configure
The configuration is /etc/dnf/automatic.conf. The file that Rocky Linux 9 and 10 ship downloads updates but
does not install them (download_updates = yes, apply_updates = no), and it covers all updates
(upgrade_type = default). Change these lines:
[commands]
upgrade_type = security
download_updates = yes
apply_updates = yes
reboot = never
[emitters]
emit_via = stdio
| Setting | Meaning |
|---|---|
upgrade_type = security |
Only updates with a security advisory. default installs all updates. |
apply_updates = yes |
Install the downloaded updates. |
reboot |
never, when-changed (after any update) or when-needed (after updates that need a reboot, such as the kernel or glibc). The reboot runs shutdown -r +5 by default (reboot_command). RHEL 9 and later; the dnf-automatic of RHEL 8 ignores the line. |
emit_via = stdio |
Write the report to the output of the service, which ends up in the journal. email needs a working mail setup, motd writes to the login message. |
Turn on the timer
sudo systemctl enable --now dnf-automatic.timer
systemctl list-timers 'dnf-automatic*'
dnf-automatic.timer follows the configuration file. The package also ships timers that ignore
apply_updates and download_updates: dnf-automatic-notifyonly.timer (report only),
dnf-automatic-download.timer and dnf-automatic-install.timer. Enable one timer, not several.
As shipped on Rocky Linux 9 and 10, all four timers run at 06:00 with a random delay of up to 60 minutes
(OnCalendar=*-*-* 6:00, RandomizedDelaySec=60m) and catch up after downtime (Persistent=true).
To run at a different time, override the timer:
sudo systemctl edit dnf-automatic.timer
[Timer]
OnCalendar=
OnCalendar=*-*-* 03:30
The empty OnCalendar= clears the time of the packaged timer before the new one is set.
Check what it would install
The security filter depends on the advisories (updateinfo) of the repositories: RHSA from Red Hat, RLSA from Rocky Linux, ALSA from AlmaLinux. To see what is pending:
sudo dnf updateinfo list --security
sudo dnf check-update --security
dnf check-update exits with code 100 when updates are available and 0 when there are none.
Packages from repositories without advisories never count as security updates, so upgrade_type = security
leaves them out. Update them on a schedule of your own, or set upgrade_type = default.
Check that it ran
journalctl -u dnf-automatic.service --since -2d
sudo dnf history list | head
The journal shows the report of each run, ending with a line such as Updates completed at Thu Nov 26 02:52:43 2026; dnf history lists the transactions with their date.
Reboots
Kernel and glibc updates need a reboot. dnf needs-restarting -r exits with code 1 when the server needs one
and 0 when it does not. With reboot = when-needed, dnf-automatic reboots on its own after such updates.
On RHEL 8, dnf-automatic does not reboot, whatever the configuration says. A cron job that asks
needs-restarting does it instead:
echo '30 4 * * * root dnf needs-restarting -r >/dev/null || /usr/sbin/shutdown -r +5' | sudo tee /etc/cron.d/reboot-when-needed
When to reboot after updates covers planning the reboot and checking that services come back.
Amazon Linux 2023
Amazon Linux 2023 locks each server to the repository version of the AMI it was built from, and each new set of package updates is a new repository version. dnf-automatic alone therefore finds nothing to install. List the newer versions and move to one with:
sudo dnf check-release-update
sudo dnf upgrade --releasever=<version>
Vulnpocalypse checks every day that dnf-automatic or another update timer is active, and counts the security updates that are still waiting.
Sources
- DNF Automatic: timers,
automatic.confoptions and defaults - dnf needs-restarting:
-rexit codes - dnf(8): check-update: exit code 100
- systemd.timer(5):
OnCalendar=reset with an empty value - Amazon Linux 2023: deterministic upgrades
Check your servers every day
The Vulnpocalypse collector reports the packages and settings of a server once a day, and the digest lists what to fix, most urgent first.
Vulnpocalypse