In this article, I’ll explain how to configure automatic updates in Debian/Ubuntu using the unattended-upgrades package. We’ll cover two approaches: manual configuration in the terminal and tasks for an Ansible playbook. We’ll also look at how to restrict automatic installation to security updates only. The example uses a virtual machine running Debian 13.
🖐️Hey!
Subscribe to our Telegram channel @r4ven_me📱, so you don’t miss new posts on the website 😉. If you have questions or just want to chat about the topic, feel free to join the Raven chat at @r4ven_me_chat🧐.
Introduction
In a production environment, keeping the system up to date and promptly installing updates that address known vulnerabilities is critical. In practice, however, this is not always possible because of constraints imposed by installed software. For example, applications running on a server may be incompatible with newer versions of system components because they are no longer maintained or have strict dependency requirements.
In these circumstances, a compromise is to configure automatic installation of security updates, which minimize changes affecting user-facing software and applications while reducing the system’s overall exposure to vulnerabilities.
However, it is important to understand the limitations of this approach:
- installing only security updates does not eliminate the risk of conflicts with outdated software;
- some vulnerabilities may exist in the applications themselves and cannot be fixed by system updates;
- the overall level of security remains limited because the system does not receive other updates, including new features and bug fixes.
This approach should therefore be considered a temporary risk-reduction measure, not a complete replacement for regularly updating the entire software stack.
Software used in this article:
| Software | Version |
|---|---|
| Debian | 13.4 |
Configuring automatic updates in Linux
Option 1: manual configuration in the server terminal
You can enable automatic updates with a few commands, but first you need to install the appropriate packages.
☝️ To configure the machine manually in the terminal, you need access to the root account or permission to run the apt and dpkg package managers through sudo.
In this example, we’ll use an account with sudo access, so the command is:
sudo apt install -y unattended-upgrades apt-listchangesAfter installing the required packages, reconfigure automatic updates:
sudo dpkg-reconfigure --priority=low unattended-upgrades📝 The --priority=low flag lowers the threshold for displaying configuration questions, including those that are normally hidden.
In the dialog that appears, enable automatic updates by selecting Yes (Да in the Russian-language screenshot below).

📝 On a system with an English locale, select Yes.
You will then find two new files in the apt package manager configuration directory:
# Enables daily checks for updates
/etc/apt/apt.conf.d/20auto-upgrades
# Configures automatic update installation
/etc/apt/apt.conf.d/50unattended-upgradesBy default, updates are configured to come from all channels except those that have not been tested:
╭─(12:58:49)-(0)-(llm-b01-p)-[~]
╰─[root]# grep -vE '^//' /etc/apt/apt.conf.d/50unattended-upgrades
grep -vE '^//' /etc/apt/apt.conf.d/50unattended-upgrades
Unattended-Upgrade::Origins-Pattern {
// Codename based matching:
// This will follow the migration of a release through different
// archives (e.g. from testing to stable and later oldstable).
// Software will be the latest available for the named release,
// but the Debian release itself will not be automatically upgraded.
"origin=Debian,codename=${distro_codename},label=Debian";
"origin=Debian,codename=${distro_codename},label=Debian-Security";
"origin=Debian,codename=${distro_codename}-security,label=Debian-Security";
// Archive or Suite based matching:
// Note that this will silently match a different release after
// migration to the specified archive (e.g. testing becomes the
// new stable).
};
Unattended-Upgrade::Package-Blacklist {
// The following matches all packages starting with linux-
// Use $ to explicitely define the end of a package name. Without
// the $, "libc6" would match all of them.
// Special characters need escaping
// The following matches packages like xen-system-amd64, xen-utils-4.1,
// xenstore-utils and libxenstore3.0
// For more information about Python regular expressions, see
// https://docs.python.org/3/howto/regex.html
};For typical use cases where packages need to be kept up to date, this configuration is sufficient and meets basic system security and maintenance requirements.
However, if the server runs outdated software or applications that depend on specific dependency versions and are incompatible with updated libraries, this update policy may cause failures or break some functionality.
In these scenarios, it makes sense to restrict automatic installation to updates from the security repository. This reduces the risk of introducing changes that could affect applications and user-facing software.
To do this, remove the unrelated sources from the Unattended-Upgrade::Origins-Pattern block in /etc/apt/apt.conf.d/50unattended-upgrades, leaving only entries that match the security repository.
A minimal configuration looks like this:
Unattended-Upgrade::Origins-Pattern {
"origin=Debian,codename=${distro_codename}-security,label=Debian-Security";
};Keep in mind that even installing security patches alone does not completely eliminate the risk of breaking software that depends on specific dependency versions. Vulnerability fixes may affect libraries and components used by applications.
For this reason, it is recommended to:
- regularly review the
unattended-upgradeslogs (/var/log/unattended-upgrades/unattended-upgrades.logand/var/log/unattended-upgrades/unattended-upgrades-dpkg.log); - monitor changes to the packages being installed;
- whenever possible, test updates in a test environment before applying them in production.
Option 2: configuring updates in an Ansible playbook
The first approach, manual configuration, is suitable for small infrastructures without centralized automation and for scenarios that require fine-tuning, where automatically installing all updates could break older software.
In larger infrastructures, virtual machines and servers are usually configured automatically using tools such as Terraform, OpenTofu, SaltStack, and Ansible. The previous approach may therefore be unsuitable if, for example, we want to deploy and configure a group of virtual machines at once.
In this scenario, it makes more sense to add the appropriate tasks to the main configuration playbook.
Here is an example of initial server setup tasks that install all updates available at the time of execution and enable automatic updates:
tasks:
- name: Update the system
ansible.builtin.apt:
update_cache: true
upgrade: dist
autoremove: true
- name: Install packages for automatic updates
ansible.builtin.apt:
name:
- unattended-upgrades
- apt-listchanges
state: present
- name: Enable unattended-upgrades
ansible.builtin.copy:
dest: /etc/apt/apt.conf.d/20auto-upgrades
content: |
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "1";
owner: root
group: root
mode: '0644'
- name: Configure security updates
ansible.builtin.copy:
dest: /etc/apt/apt.conf.d/50unattended-upgrades
content: |
Unattended-Upgrade::Origins-Pattern {
"origin=Debian,codename=${distro_codename}-security,label=Debian-Security";
"origin=Ubuntu,archive=${distro_codename}-security";
};
Unattended-Upgrade::Remove-Unused-Dependencies "true";
owner: root
group: root
mode: '0644'
- name: Ensure the unattended-upgrades service is enabled and running
ansible.builtin.systemd:
name: unattended-upgrades
enabled: true
state: started⚠️ Warning
In this playbook, the first task (upgrade: dist) installs all available updates once, without restricting them to security updates. After that, unattended-upgrades automatically installs only security updates because Origins-Pattern contains only security repositories.
If the server runs software that depends on specific versions, remove or replace the first task.
The Origins-Pattern block contains two lines: the first is for Debian, and the second is for Ubuntu. The line that does not apply to the system simply matches nothing and causes no interference, so the same playbook works on both distributions.
The Unattended-Upgrade::Remove-Unused-Dependencies "true" setting enables automatic removal of unused dependencies.
Automatic reboots are disabled by default in this setup. If you want the server to reboot without administrator intervention after updates that require it (such as kernel updates), add these two settings to the content field of the “Configure security updates” task:
Unattended-Upgrade::Automatic-Reboot "true";
Unattended-Upgrade::Automatic-Reboot-Time "03:00";Unattended-Upgrade::Automatic-Reboot— the server will reboot if this is required to apply updates;Unattended-Upgrade::Automatic-Reboot-Time— the reboot will take place at the specified time rather than immediately after installation.
⚠️ Warning
The reboot happens without warning and interrupts services running on the server. Enable it only if this is acceptable.
Conclusion
Automatic updates are an essential practice for maintaining system security. In typical operating scenarios, the default settings are sufficient to keep packages up to date without manual intervention.
When a server runs outdated software or applications that depend on specific dependency versions, it is better to restrict automatic updates to security patches and update everything else manually as needed. This approach reduces the risk of breaking sensitive software, but does not eliminate it completely or address every potential vulnerability.
Even in this mode, additional oversight is necessary: reviewing logs, tracking changes, and testing updates whenever possible. In the long term, this approach should be considered temporary, with a plan to modernize or replace the outdated software if possible.
👨💻And…
Don’t forget about our Telegram channel 📱 and chat
Or maybe you want to become a co-author? Then click here🔗
💬 All the best ✌️
That should be it. If not, check the logs 🙂


