24/7 ACTIVE THREAT INTELLIGENCE & NODE TELEMETRY MON - FRI: 10AM - 5PM
Home / Blog / Infrastructure & Linux

How to configure automated security updates on Linux

How to configure automated security updates on Linux

Keeping your system up-to-date with the latest packages and security updates can be a tedious task. Most users forget to do it, leaving them vulnerable to countless threats. Automate security (and other package) updates with the utility Unattended Upgrades on Debian or Ubuntu.

You can set up automated security updates on Linux by installing a helpful utility called unattended-upgrades.

Install it running the following command:

command
sudo apt install unattended-upgrades

After the installation completes, you can enable and start the unattended-upgrades service by running the following commands:

command
sudo systemctl enable unattended-upgrades

And this one:

command
sudo systemctl start unattended-upgrades

Configure unattended-upgrades file

The unattended-upgrades configuration file is found in the /etc/apt/apt.conf.d directory.

Access the configuration file with the following command:

command
sudo nano /etc/apt/apt.conf.d/50unattended-upgrades

The unattended-upgrades package ignores lines that start with // as that line is considered to be a comment.

If you want a repository to update automatically, you need to remove // from that line.

For our purposes, we only need to remove // from the “security” line.

The Unattended-Upgrade::Package-Blacklist section of the config file allows you to block upgrades for specific packages.

You can also use hold option by running following command:

command
sudo apt-mark hold package-name

Enable Automatic Upgrades

The final step to enable automatic updates is to edit the auto-upgrades file with the command:

command
sudo nano /etc/apt/apt.conf.d/20auto-upgrades
command
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "1";
APT::Periodic::AutocleanInterval "7";

Testing automatic upgrades

To verify that the automatic upgrades are set up correctly perform a dry run. The dry run command ensures that the update is only a simulation and that no actual changes will take place. Use the command:

command
sudo unattended-upgrades --dry-run --debug
← PREVIOUS ARTICLE
How to avoid FOMO in crypto trading
NEXT ARTICLE →
Securing Apache2 with ModSecurity