How to Configure Automatic Package Updates on CentOS 8

Security updates, as most of you would agree, are very important. Under Linux it is always advisable to keep the installed packages up to date, especially when it comes to security. In general, users should apply security updates to their Linux systems within 30 days of the release.

In this tutorial, we will show you how to set up automatic update packages on CentOS 8. This ensures that the system automatically downloads packages and performs updates without manual intervention.

On the CentOS 8 system, we have two ways to set up automatic update packages. We can use the CLI mode with the utility "dnf-automatic" and the web-based environment that can be implemented via Cockpit Server Management.

Setup Automatic Update using Dnf-automatic

The dnf-automatic is systemd units that can download package upgrades and apply them automatically.  The dnf-automatic provides three different systemd units to control the automatic update.

Below are three systemd units provided by dnf-automatic.

  • dnf-automatic-download.timer for download only
  • dnf-automatic-install.timer for download package updates and install
  • dnf-automatic-notifyonly.timer will only notify via the omitter configuration

The dnf-automatic are not installed by default on the CentOS system, it's available on the BaseOS repository.

Install the dnf-automatic using the following command.

sudo dnf install dnf-automatic

Once the installation is complete, go to the '/etc/dnf' directory and edit the configuration 'automatic.conf'.

cd /etc/dnf/
vim automatic.conf

On the '[commands]' section, change the 'upgrade_type' as you need. You can use 'default' for upgrading all packages or use the 'security' option to upgrade all packages related security.

[commands]
upgrade_type = default
download_updates = yes

On the '[emitters]' section, uncomment the 'system_name' option and change the value with your hostname. Then change the 'emit_via' option to motd, so you will be displayed about package updates on every login.

[emitters]
system_name = hakase-centos8
emit_via = motd

Other options for 'emit_via' configuration are 'stdio' which is default configuration and 'email' for sending package updates information to your email.

Now go to the '[email]' section and change each configuration with your own.

[email]
email_from = [email protected]
email_to = root
email_host = localhost

Save and close.

Automatic Download Package Upgrades

Next, start the dnf-automatic timer and add it to the system boot.

sudo systemctl enable --now dnf-automatic.timer

Now check the status of the dnf-automatic timer.

sudo systemctl list-timers *dnf-*

Now you will see two different systemd units timer.

The dnf-makecache unit will run the dnf-makecache service for updating cache packages, and the dnf-automatic unit will run the dnf-automatic service for downloading package upgrades.

Configure DNS automatic updates

Now on every login action to the CentOS 8 server, you will see the summary of package upgrade downloaded as a motd (message of the day).

Package updates message when login

All package upgrades have been download automatically through the 'dnf-automatic' timer service.

Automatic Install Package Upgrades

For the automatic installation of package upgrades, you can run the 'dnf-automatic-install' timer service.

Start the 'dnf-automatic-install' timer service and add it to the system boot.

sudo systemctl enable --now dnf-automatic-install.timer

After that, check the status of the dnf-automatic timer.

sudo systemctl list-timers *dnf-*

You will get the 'dnf-automatic-install' timer on the list.

Install timer

Now on every login action to the CentOS 8 server, you will see the summary of package upgrade applied as a motd (message of the day).

Package updates applied

And all package upgrades have been applied automatically through the 'dnf-automatic-install' timer service.

Setup Automatic Update via Cockpit

Open your web browser, type the server IP address following by the default cockpit port '9090' and log in with your user and password.

https://10.5.5.70:9090/

Once you've logged in, go to the "Software Updates" menu and turn on the automatic updates button.

Use Cockpit to configure automatic package updates

Now you will be asked for installing the package 'dnf-automatic', click the 'Install' button.

Install dnf-automatic via cockpit

Once the installation is complete, select the update type that suits you and choose the time for updating packages.

Installation complete

Now the dnf-automatic timer is up and running on the system.

Click on the "Services" menu and select the "Timers" tab.

Services and timers

You will get the dnf-makecache and dnf-automatic-install timers are activated.

As a result, you've configured the CentOS 8 automatic update using the dnf-automatic through the cockpit server management.

Reference

Share this page:

0 Comment(s)