How to configure automated security updates on Debian automatically

Debian provides a package called “unattended-upgrades” to automate security updates. Here’s how you can configure it:

  1. Install the unattended-upgrades package:
sudo apt-get install unattended-upgrades
  1. Open the configuration file:
sudo nano /etc/apt/apt.conf.d/50unattended-upgrades
  1. Enable the automatic upgrade of security updates:
Unattended-Upgrade::Allowed-Origins {
"${distro_id}:${distro_codename}-security";
// "${distro_id}:${distro_codename}-updates";
// "${distro_id}:${distro_codename}-proposed";
// "${distro_id}:${distro_codename}-backports";
};
  1. Enable email notifications for upgrades:
Unattended-Upgrade::Mail "root";
Unattended-Upgrade::MailOnlyOnError "true";
  1. Save and close the configuration file.
  2. Update the package index and upgrade the system to ensure that the latest security updates are installed:
sudo apt-get update
sudo apt-get upgrade
  1. Verify that the unattended upgrades are working:
sudo unattended-upgrades --dry-run --debug

This should give you an overview of what upgrades will be performed, without actually installing any packages.

By default, unattended upgrades run daily, but you can change the schedule by modifying the “Unattended-Upgrade::Periodic::” settings in the configuration file.

Note: Before enabling automatic security updates, it is recommended to test the upgrades on a test environment to ensure that there are no unintended consequences.

Leave a Comment