Automatic Security Updates with DNF

The Dandified YUM tool, DNF, has become a powerful package manager for systems running Fedora. As it looks now, it will become also the default package manager for CentOS 8 and RHEL 8. One of the benefits from dnf is the option to retrieve security information very easily. This allows us to use it for automatic security patching of our Linux systems. Let’s explore the options and see how dnf-automatic can help us with fully automated patching.

Security Patches

The newer versions of Fedora use DNF. To check available security patches, use the dnf command.

dnf updateinfo list security

While this output is helpful, we want more automation, right? Instead of creating our own shell script for the cause, we leverage the dnf-automatic utility to do the heavy lifting for us.

Install and Configure dnf-automatic

We can deploy updates automatically with the package dnf-automatic. This package simplifies automatic patching, by running on a timer and then apply updates. You can configure it to just install security updates.

Note: For those who previously used YUM, this is similar to the “yum -update security” command, but better.

First step to using dnf-automatic, is to install the package.

dnf install dnf-automatic

The common output of command installation should show up.

Configuration of automatic updates

Next step to apply updates security updates only, is to adjust this /etc/dnf/automatic.conf. Configure at least the following settings:

apply_updates = yes
download_updates = yes
upgrade_type = security

Scheduled timers

After applying the changes, you are done with the configuration part. Now check the status of the related timer, to see if that is activated.

systemctl status dnf-automatic.timer

This timer will be disabled by default. If this applies to your system as well, enable the timer and start it.

systemctl enable dnf-automatic.timer && systemctl start dnf-automatic.timer

That looks much better. Time for the last steps and validate that everything works as expected.

Testing dnf-automatic

After the configuration, let’s test it. This way we know we made the right changes to the file. Run dnf-automatic manually to check if it runs properly.

dnf-automatic

If you have any security patches available, you will see some output on the screen. When none updates are available, the output will remain empty.

Unfortunately, the logging of dnf-automatic is limited. You can view the installed updates in /var/log/dnf.rpm.log file. This will show what packages are upgraded and installed.

Additional Steps

With software and security patching it happens that related processes need to be restarted. DNF has a plugin command available to test this.

dnf needs-restarting

If nothing has to be done, the output will be empty. Otherwise, it will show you the processes which need a restart. Depending on what has been patched, that can be a long list. Sometimes a fresh system reboot is easier (and safer).

Measure After Patching

While applying security patches automatically has a lot of pros, ensure that your system monitoring is in place. Also, configure remote logging on your systems by using a remote syslog server. This gives you an audit trail of the packages installed and any changes to them. When something breaks, you know at least what happened.

Happy patching!

Feedback

Small picture of Michael Boelen

This article has been written by our Linux security expert Michael Boelen. With focus on creating high-quality articles and relevant examples, he wants to improve the field of Linux security. No more web full of copy-pasted blog posts.

Discovered outdated information or have a question? Share your thoughts. Thanks for your contribution!

Mastodon icon