Update Strategy
Before updating the system kernel, services or programs, remember to check for any software that might break as a result of a system update/upgrade.
the machine might be using an old unpatched software that is not compatible with newer versions of your distribution.
Check Package Manager
Verify package repositories are configured correctly. Depending on the package management in use one of the following command groups may provide the needed information:
Ensure GPG keys are configured
Validate Packages before Installation
Check Package Integrity
Debian-based
Redhat-based
Updating Debian-based systems
Manual Security Update
To manually install the security-related updates without installing non-security updates, just run the following line of code:
If you want to see if there are any security-related updates available, but don't want to see any non-security updates, use the unattended-upgrade command, like so:
To manually install the security-related updates without installing non-security updates, just run the following line of code:
Debian Auto Update
You can set up automated security updates on Debian by installing a helpful utility called unattended-upgrades
update your system with
apt update && apt upgrade
.Install it running the following command:
After the installation completes, you can enable and start the
unattended-upgrades
service by running the following commands:This ensures that the service runs on system startup and is persistent throughout.
You now need to make changes to the configuration file. The default configuration file can be found here at
/etc/apt/apt.conf.d/50unattended-upgrades
. Open it with the text editor of your choice.
The unattended-upgrades package ignores lines that start with //
, as that line is considered to be a comment. Therefore, if you want a repository to update automatically, you need to remove //
from that line.
In our example, remove //
from the “security” line if it’s there, "origin=Debian,codename=${distro_codename},label=Debian-Security";
. This section should look like the following:
Blacklisting Packages
The Unattended-Upgrade::Package-Blacklist
section of the configuration file allows you to block upgrades for specific packages.
To block upgrades for specific packages, add the desired package name to the list. In this example, add “apache2” and “vim”:
Deleting Dependencies
You can explicitly set up the unattended-upgrades service to remove unused dependencies by changing the Remove-Unused-Kernel-Packages
, Remove-New-Unused-Dependencies
, and Remove-Unused-Dependencies
options to true. Remember to remove //
to uncomment these lines.
Enabling Automatic Upgrades
To enable automatic updates create a new auto-upgrades file: /etc/apt/apt.conf.d/20auto-upgrades
using text editor of your choice.
This file allows you to define how often the auto updates take place.
Update-Package-Lists:
1
enables auto-update,0
disables.Unattended-Upgrade:
1
enables auto-upgrade,0
disables.AutocleanInterval: Enables auto clean packages for
X
days. The above configuration displays 7 daysFor example,
APT::Periodic::AutocleanInterval “7”;
means that the system clears the download archive every seven days.
Enable Auto Reboot
Uncomment the line by removing the leading slashes, and change false to true, like so:
Testing The Configuration
You can perform a dry run to test the configuration. The dry run command runs a test update but no actual changes take place.
You can run the dry run test by using the command:
Ubuntu Auto Update
update your system with
apt update && apt upgrade .
Install it running the following command:
After the installation completes, you can enable and start the
unattended-upgrades
service by running the following commands:This ensures that the service runs on system startup and is persistent throughout.
You now need to make changes to the configuration file. The default configuration file can be found here at
/etc/apt/apt.conf.d/50unattended-upgrades
. Open it with the text editor of your choice.
In our example, remove //
from the “security” line if it’s there, "${distro_id}:${distro_codename}-security";
. This section should look like the following:
Blacklisting Packages
The Unattended-Upgrade::Package-Blacklist
section of the configuration file allows you to block upgrades for specific packages.
To block upgrades for specific packages, add the desired package name to the list. In this example, add “apache2” and “vim”:
Deleting Dependencies
You can explicitly set up the unattended-upgrades service to remove unused dependencies by changing the Remove-Unused-Kernel-Packages
, Remove-New-Unused-Dependencies
, and Remove-Unused-Dependencies
options to true. Remember to remove //
to uncomment these lines.
Enabling Automatic Upgrades
To enable automatic updates create a new auto-upgrades file: /etc/apt/apt.conf.d/20auto-upgrades
using text editor of your choice.
This file allows you to define how often the auto updates take place.
Update-Package-Lists:
1
enables auto-update,0
disables.Unattended-Upgrade:
1
enables auto-upgrade,0
disables.AutocleanInterval: Enables auto clean packages for
X
days. The above configuration displays 7 daysFor example, APT::Periodic::AutocleanInterval “7”; means that the system clears the download archive every seven days.
Enable Auto Reboot
Go into the /etc/apt/apt.conf.d
directory and open the 50unattendedupgrades
file in your favorite text editor. In the vicinity of line 68, you'll see a line that says the following:
With this new configuration, Ubuntu will now reboot itself immediately after the automatic update process has completed. If you'd rather have the machine reboot at a specific time, scroll down to about line 73, where you'll see this line of code:
t. To have the machine reboot at 2:00 A.M., just uncomment this line. To have it reboot at, say, 10:00 P.M., uncomment the line and change the time to 22:00, like so:
Testing The Configuration
You can perform a dry run to test the configuration. The dry run command runs a test update but no actual changes take place.
You can run the dry run test by using the command:
Disabling Auto Updates
To disable automatic updates, just go into the /etc/apt/apt.conf.d
directory and open the 20auto-upgrades
file in your favorite text editor. What you'll see is this:
Change the parameter for that second line to 0, so that the file will now look like this:
Now, the system will still check for updates and show a message at the login screen when any are available, but it won't automatically install them. And of course, it should go without saying that you need to check your systems on a regular basis to see if updates are available. If you do prefer to leave automatic updates enabled, be sure to either enable automatic rebooting or to log in to the system at least a couple of times a week to see if it needs to be rebooted.
Updating Redhat7-based Systems
With Red Hat-based systems, which include CentOS and Oracle Linux, there's no automatic update mechanism that you can set up during installation. So, with the default configuration, you'll need to perform updates yourself:
Sometimes, you might just want to see if there are any security-related updates that are ready to be installed. Do that by running the following command:
If any security updates are available, you'll see them at the end of the command output. On the system that I just tested, there was only one security update available, which looks like this:
. If the only thing you want to install is just the security updates, run the following command:
CentOS 7 Auto Update
To configure it, go into the /etc/yum
directory, and edit the yum-cron.conf
file. At the top of the file, you'll see this:
This lists the various types of upgrades we can do. The last line shows that we're set to update everything.
Let's say that you only want security updates to get applied automatically. Just change the last line to the following:
On lines 15 and 20, you'll see this line:
This indicates that by default, yum-cron is only set to automatically download updates, but not to install them.
If you want the updates to get automatically installed, change the apply_updates
parameter to yes
.
Note that unlike Ubuntu, there's no setting to make the system automatically reboot itself after an update
e, the email_to = line is set to send messages to the root user account. If you want to receive messages at your own account, just change it here.
To see the messages, you'll need to install a mail reader program, if one isn't already installed. (It hasn't been installed if you chose Minimal installation when you installed the operating system.) Your best bet is to install mutt, like so:
As with all operating systems, certain updates will require that the system be restarted.
And how do you know when the system needs to be restarted? With the needs-restarting command, of course. First, though, you need to make sure that needs-restarting is installed on your system. Do that with the following line of code:
Once the package is installed, there are three ways to use needs-restarting. If you just run the command without any option switches, you'll see the services that need to be restarted and the packages that require you to reboot the machine. You can also use the -s or -r options, as shown here:
Command | Explanation |
---|---|
sudo needs-restarting | This shows the services that need to be restarted, and the reasons why the system might need to be rebooted. |
sudo needs-restarting -s | This only shows the services that need to be restarted. |
sudo needs-restarting -r | This only shows the reasons why the system needs to be rebooted. |
Updating Red Hat 8-based systems
The difference between yum and dnf is that dnf has a different automatic update mechanism. Instead of installing the yum-cron
package, you'll now install the dnf-automatic
package, like so:
In the /etc/dnf
directory, you'll see the automatic.conf
file, which you'll configure the same way as you did the yum-cron.conf file for CentOS 7. Instead of working as a cron job, as the old yum-cron did, dnf-automatic
works with a systemd timer. When you first install dnf-automatic
, the timer is disabled. Enable it and start it by running the following line of code:
Verify that it's running by typing the following line of code:
If it started successfully, you should see something like this:
Last updated