We all know that keeping our systems up to date is something that should be on the top of any sysadmins list and with Windows it’s pretty easy, in fact, it’s harder to stop Microsoft from updating your systems than it is to plan an update schedule!
As I have been increasingly using CentOS as my go-to server Operating System I thought it was about time to ensure that it was updating automatically and not having to wait for me to log in and run ‘yum update’, as because its Linux I rarely have to log in to these servers as they just work!
So how do you get Linux CentOS to automatically update itself?
Turns out it’s actually pretty simple, you’ll need to ensure you have the EPEL repository installed which can be achieved with the following command:
yum -y install epel-release
Once the EPEL repo is installed you need to install yum-cron to enable automatic updates, this is done by running the following command:
yum -y install yum-cron
Now you have yum-cron package installed you’ll need to edit the config file which is located here /etc/yum/yum-cron.conf
You will need to edit the apply_updates line to ensure that its run, so change = no to = yes
apply_updates = yes
Now I like to know when things change just so I can keep an eye on it and as I have an email server running in my environment I also changed the following segment of the config file so it will send me reports when it runs.
[email]
# The address to send email messages from.
# NOTE: 'localhost' will be replaced with the value of system_name.
email_from = [email protected]
# List of addresses to send messages to.
email_to = [email protected]
Obviously change the email addresses to whatever is relevant to you, then close and save the file.
The only thing left to do now is to enable and start the service, enable it at boot
systemctl enable yum-cron.service
Then to start the service you just need to run:
systemctl start yum-cron.service
If like me you can be a paranoid and like to check everything is working and not just assume it is you can check the status of the service as follows:
systemctl status yum-cron.service
Which should report something like the below, hopefully!
Now, yum-cron should run daily and email you when it updates the system so you can keep an eye on things but not have to worry about logging on and running ‘yum update’.
Hopefully, you found this helpful I know I did, drop us a message or leave a comment if you have anything to add.