Yum-cron – Install Security Updates Automatically in CentOS 7

[‘

n

In a world of emerging and ever-evolving cyber threats and breaches, applying security updates will go a long way in safeguarding your system against potential threats. And what a joy it would be if the application of these updates is done automatically without your intervention!

n

This means that you would worry less about manually updating your system and focus on other system administration tasks.

n

Recommended Read: dnf-automatic – Install Security Updates Automatically in CentOS 8

n

In this tutorial, you will learn how to use yum-cron to install and configure security updates automatically on your CentOS 7 system.

n

So what is Yum-Cron?

n

Yum-cron is a yum module and command-line tool that allows a user to configure a cron job for the Yum package manager.

n

Step 1: Installing Yum-cron Utility in CentOS 7

n

The Yum-cron comes preinstalled on CentOS 7, but if for whatever reason it is not present, you can install it by running the command.

n

# yum install yum-cronrn

n

Install Yum-Cron in CentOS 7
Install Yum-Cron in CentOS 7

n

Once the installation is complete, confirm the existence of yum-cron utility by running the rpm command with grep command.

n

# rpm -qa | grep yum-cronrn

n

Verify Yum-Cron Installed
Verify Yum-Cron Installed

n

Step 2: Configuring Automatic Security Updates in CentOS 7

n

After the successful installation of the yum-cron utility, you need to configure it to automatically retrieve security updates and update your system. There are 2 kinds of updates: the default update which is initialized using the yum update command, minimal update and finally the security update.

n

In this guide, we will configure the system to automatically receive security updates. So open and edit the yum-cron.conf file located in the path shown.

n

# vi /etc/yum/yum-cron.confrn

n

Locate the string update_cmd. By default, this is set to default. Now edit and set the value to ‘security’.

n

update_cmd = securityrn

n

Next, locate the update_messages parameter and ensure its value is set to ‘yes’.

n

update_messages = yesrn

n

Likewise, do the same for download_updates as well as apply_updates.

n

download_updates = yesrnapply_updates = yesrn

n

Your configuration should look as shown below.

n

Configure Automatic Security Updates on CentOS 7
Configure Automatic Security Updates on CentOS 7

n

Save and exit the configuration file.

n

For the changes to come into effect, start and enable the yum-cron daemon or service on boot as shown.

n

# systemctl start yum-cronrn# systemctl enable yum-cronrn# systemctl status yum-cronrn

n

Check Yum-Cron Service Status
Check Yum-Cron Service Status

n

Step 3: How to Exclude Packages from Updating in Yum

n

Sometimes, you may need to maintain the version of packages and not update them due to compatibility issues that may arise with other applications that depend on the package. Sometimes, this may even include the kernel itself.

n

To achieve this, head back to the yum-cron.conf configuration file. At the bottom, in the [base] section, append a line with the ‘exclude’ parameter and define the packages you want to exclude from updating.

n

exclude = mysql* php* kernel*rn

n

Yum Exclude Packages from Updating
Yum Exclude Packages from Updating

n

All package names that begin with mysql & php will be excluded from automatic updates.

n

Restart yum-cron to effect the changes.

n

# systemctl restart yum-cronrn

n

Step 4: Checking yum-cron Logs

n

The yum-cron logs are stored in /var/log/yum.log file. To view the packages that have been updated run the cat command.

n

# cat /var/log/yum.log  | grep -i updatedrn

n

Automatic system updates are controlled by a cron job that runs daily and is stored in the /var/log/cron file. To check the logs for the daily cron job run.

n

# cat /var/log/cron | grep -i yum-dailyrn

n

Your CentOS 7 system is now fully configured for automatic security updates and you won’t have to stress over manually updating your system.

n

‘]