Executive Summary
Ubuntu uses the unattended-upgrades package, APT configuration files, and systemd timers to automatically download and install permitted package updates, including security patches.
Although automatic upgrades improve security, they can introduce operational risks on production servers, including unexpected service restarts, dependency changes, and application compatibility issues.
The recommended approach for production servers with controlled maintenance windows is to:
Disable automatic package installation through an APT configuration override.
Disable apt-daily-upgrade.timer.
Keep apt-daily.timer enabled to refresh package lists automatically.
Leave the unattended-upgrades package installed.
Install security patches manually during scheduled maintenance windows.
Disabling apt-daily-upgrade.service directly is insufficient because it is normally a static systemd service activated by a timer.
Quick Implementation
Execute the following commands to implement the recommended configuration:
sudo tee /etc/apt/apt.conf.d/99-disable-unattended-upgrades > /dev/null <<'EOF'
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "0";
EOF
sudo systemctl disable --now apt-daily-upgrade.timer
sudo systemctl enable --now apt-daily.timer
Verify the configuration:
apt-config dump | grep APT::Periodic
systemctl is-enabled apt-daily-upgrade.timer
systemctl is-enabled apt-daily.timer
systemctl list-timers --all | grep apt
Expected results:
| Component | Expected state |
|---|
| Automatic package list updates | Enabled |
| Automatic package installation | Disabled |
apt-daily.timer | Enabled |
apt-daily-upgrade.timer | Disabled |
| Manual APT operations | Available |
| Unattended-upgrades package | Remains installed |
Security warning: After implementing this configuration, the system administrator becomes responsible for installing security updates.
1. Introduction
Ubuntu includes an automatic update mechanism called unattended-upgrades, which periodically installs security updates and other permitted package upgrades without administrator intervention.
While this functionality is useful for desktops and general-purpose servers, it may not be desirable in production environments running critical applications such as MySQL, Apache, Nginx, or Java application servers.
Unexpected package upgrades can introduce dependency changes, restart services, or affect application availability. For this reason, system administrators may prefer to perform upgrades manually during scheduled maintenance windows.
This article explains how Ubuntu's automatic upgrade mechanism works, how to disable it properly, and how to verify the resulting configuration.
2. Understanding Ubuntu's Automatic Update Mechanism
Ubuntu uses systemd services and timers to manage automatic package updates.
The four main systemd units involved are:
| Systemd unit | Purpose |
|---|
apt-daily.timer | Schedules package list updates. |
apt-daily.service | Updates package lists and performs related maintenance. |
apt-daily-upgrade.timer | Schedules automatic package upgrades. |
apt-daily-upgrade.service | Executes automatic upgrades and cleanup activities. |
The automatic upgrade process follows this execution sequence:
apt-daily-upgrade.timer
|
v
apt-daily-upgrade.service
|
v
/usr/lib/apt/apt.systemd.daily install
|
v
unattended-upgrade
|
v
Package installation
Whether packages are actually installed depends on the effective APT configuration.
There is also a separate service called unattended-upgrades.service, which primarily coordinates unattended upgrades with system shutdown. It should not be confused with apt-daily-upgrade.service.
3. What Is apt-daily-upgrade.service?
The apt-daily-upgrade.service is a systemd service responsible for executing scheduled package upgrades and cleanup activities.
Its configuration can be inspected using:
systemctl cat apt-daily-upgrade.service
A typical service definition contains:
[Unit]
Description=Daily apt upgrade and clean activities
After=apt-daily.service network.target network-online.target
ConditionACPower=true
[Service]
Type=oneshot
ExecStart=/usr/lib/apt/apt.systemd.daily install
KillMode=process
TimeoutStopSec=900
The exact definition may vary depending on the Ubuntu and APT versions.
The important parameter is:
Type=oneshot
This indicates that the service performs a specific task and terminates when the task is completed. Unlike Apache or MySQL, it does not run continuously.
Consequently, seeing the following status is perfectly normal:
Active: inactive (dead)
This does not mean that automatic upgrades are disabled.
4. Disabling Unattended Upgrades Through APT
The standard automatic upgrade configuration is located in:
/etc/apt/apt.conf.d/20auto-upgrades
Its contents typically include:
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "1";
These parameters control the following functionality:
| Parameter | Description |
|---|
Update-Package-Lists | Periodically refreshes package lists. |
Unattended-Upgrade | Periodically installs permitted package updates. |
A value of "0" disables the corresponding activity, while a positive integer specifies the interval in days.
4.1. Using a Local Configuration Override
Instead of modifying the original configuration file, it is preferable to create a separate local configuration override.
sudo nano /etc/apt/apt.conf.d/99-disable-unattended-upgrades
Add the following:
APT::Periodic::Unattended-Upgrade "0";
Alternatively, explicitly configure both parameters:
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "0";
This configuration allows Ubuntu to continue refreshing package lists automatically without installing package upgrades.
Using a separate configuration file avoids modifying the original configuration and makes the changes easier to reverse.
4.2. Disabling All Periodic APT Activities
If the objective is to disable APT's periodic maintenance mechanism entirely, use:
APT::Periodic::Enable "0";
APT::Periodic::Update-Package-Lists "0";
APT::Periodic::Unattended-Upgrade "0";
This is more restrictive than disabling unattended upgrades alone and is generally unnecessary unless all APT maintenance is managed manually.
5. Disabling the Automatic Upgrade Timer
To prevent systemd from scheduling automatic upgrade executions, disable the corresponding timer:
sudo systemctl disable --now apt-daily-upgrade.timer
The command performs two operations:
If you also want to disable automatic package list updates, execute:
sudo systemctl disable --now apt-daily.timer
However, disabling the package list update timer is not necessary if the objective is only to prevent automatic package installations.
Disabling the upgrade timer also prevents cleanup activities normally scheduled through that timer.
Stopping the timer does not interrupt an upgrade service that is already running.
6. Why Disabling the Service Itself Does Not Work
An administrator might attempt to disable automatic upgrades using:
sudo systemctl disable apt-daily-upgrade.service
However, this generally has no effect.
The reason is that apt-daily-upgrade.service is normally a static systemd service.
This can be verified using:
systemctl is-enabled apt-daily-upgrade.service
Expected output:
static
A static service does not normally contain an [Install] section defining how it should be enabled at boot.
Instead, it is activated by another systemd unit, in this case:
apt-daily-upgrade.timer
Therefore, disabling the timer rather than the service is the appropriate way to prevent scheduled execution.
7. Disabling Versus Stopping Versus Masking
Systemd provides several mechanisms for controlling services.
| Command | Effect |
|---|
systemctl disable apt-daily-upgrade.service | Generally has no effect on a static service. |
systemctl stop apt-daily-upgrade.service | Stops an active service. |
systemctl mask apt-daily-upgrade.service | Prevents future activation of the service. |
systemctl disable --now apt-daily-upgrade.timer | Stops and disables scheduled upgrade execution. |
systemctl disable --now apt-daily.timer | Stops and disables scheduled package list updates. |
7.1. Masking the Service
To completely prevent systemd from activating the upgrade service:
sudo systemctl mask apt-daily-upgrade.service
Masking normally creates a systemd override pointing the unit to /dev/null.
This prevents the service from being started manually or through another systemd unit.
To reverse the operation:
sudo systemctl unmask apt-daily-upgrade.service
Masking is generally unnecessary because disabling the timer and configuring APT appropriately is sufficient.
Additionally, masking the service does not prevent other programs from invoking unattended-upgrade directly.
If the timer remains enabled while the service is masked, systemd may generate errors when attempting to activate the service.
7.2. Do Not Interrupt an Active Upgrade
Before stopping an upgrade service, verify whether an upgrade is currently running:
systemctl status apt-daily-upgrade.service
If packages are actively being installed, allow the process to finish. Interrupting package installation can leave packages partially configured or the package database in an inconsistent state.
8. Verifying the Configuration
8.1. Check the Effective APT Configuration
apt-config dump | grep APT::Periodic
The recommended configuration should include:
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "0";
This command is particularly useful because it displays the effective configuration after processing the APT configuration files.
8.2. Check Systemd Unit States
systemctl is-enabled apt-daily.service \
apt-daily.timer \
apt-daily-upgrade.service \
apt-daily-upgrade.timer
The expected configuration is:
| Systemd unit | Expected state |
|---|
apt-daily.service | static |
apt-daily.timer | enabled |
apt-daily-upgrade.service | static |
apt-daily-upgrade.timer | disabled |
8.3. Check Scheduled Timers
systemctl list-timers --all | grep apt
8.4. Check the Upgrade Service Status
systemctl status apt-daily-upgrade.service
8.5. Check Whether the Upgrade Timer Is Active
systemctl is-active apt-daily-upgrade.timer
Expected output:
inactive
8.6. Review the Service Execution History
journalctl -u apt-daily-upgrade.service
To review only the last seven days:
journalctl -u apt-daily-upgrade.service --since "7 days ago"
To monitor service messages in real time:
journalctl -fu apt-daily-upgrade.service
8.7. Review Unattended Upgrade Logs
sudo less /var/log/unattended-upgrades/unattended-upgrades.log
Review the APT package installation history:
sudo less /var/log/apt/history.log
Review the dpkg installation history:
sudo less /var/log/dpkg.log
9. Performing Manual Package Upgrades
Disabling unattended upgrades does not interfere with normal APT operations.
Refresh Package Lists
sudo apt update
Display Available Upgrades
apt list --upgradable
Simulate an Upgrade Without Installing Packages
apt -s upgrade
Install Available Upgrades
sudo apt upgrade
Perform a Full Package Upgrade
sudo apt full-upgrade
Unlike a regular apt upgrade, a full upgrade may remove installed packages to resolve dependency changes. Review the proposed changes before proceeding.
Remove Unnecessary Packages
sudo apt autoremove
Clean the Package Cache
sudo apt autoclean
Check Whether a System Reboot Is Required
if [ -f /var/run/reboot-required ]; then
cat /var/run/reboot-required
else
echo "No reboot required"
fi
Identify Packages Requiring a Reboot
if [ -f /var/run/reboot-required.pkgs ]; then
cat /var/run/reboot-required.pkgs
fi
These operations can be performed during a scheduled maintenance window.
10. Re-enabling Unattended Upgrades
To restore automatic upgrades, first remove the local configuration override:
sudo rm /etc/apt/apt.conf.d/99-disable-unattended-upgrades
Reconfigure the unattended-upgrades package:
sudo dpkg-reconfigure unattended-upgrades
Select Yes when prompted.
If the upgrade service was previously masked, unmask it:
sudo systemctl unmask apt-daily-upgrade.service
Enable and start both timers:
sudo systemctl enable --now apt-daily.timer
sudo systemctl enable --now apt-daily-upgrade.timer
Finally, verify the effective configuration:
apt-config dump | grep APT::Periodic
And verify the scheduled timers:
systemctl list-timers --all | grep apt
11. Recommended Configuration for Production Servers
For production servers where package installation is managed manually, the following configuration provides a balance between operational stability and package update awareness.
Create a local APT configuration override:
sudo tee /etc/apt/apt.conf.d/99-disable-unattended-upgrades > /dev/null <<'EOF'
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "0";
EOF
Keep automatic package list updates enabled:
sudo systemctl enable --now apt-daily.timer
Disable scheduled automatic upgrades:
sudo systemctl disable --now apt-daily-upgrade.timer
The resulting configuration provides:
Automatic package list updates.
No scheduled automatic package installation through the standard APT upgrade mechanism.
Administrator-controlled maintenance windows.
Continued availability of manual APT operations.
Reduced risk of unexpected service restarts caused by unattended package upgrades.
An easily reversible configuration.
There is no need to uninstall the unattended-upgrades package or mask the associated systemd service.
Other update mechanisms, such as third-party management agents, custom cron jobs, and Snap automatic updates, are not disabled by this configuration.
12. Configuration Profiles
Three common configurations are available depending on the server's operational requirements.
| Configuration | Automatic updates | Automatic upgrades | Update timer | Upgrade timer |
|---|
| Default Ubuntu | Yes | Yes | Enabled | Enabled |
| Controlled production server | Yes | No | Enabled | Disabled |
| Fully manual maintenance | No | No | Disabled | Disabled |
Profile A: Default Ubuntu Configuration
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "1";
sudo systemctl enable --now apt-daily.timer apt-daily-upgrade.timer
Profile B: Controlled Production Server (Recommended)
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "0";
sudo systemctl enable --now apt-daily.timer
sudo systemctl disable --now apt-daily-upgrade.timer
Profile C: Fully Manual Maintenance
APT::Periodic::Enable "0";
APT::Periodic::Update-Package-Lists "0";
APT::Periodic::Unattended-Upgrade "0";
sudo systemctl disable --now apt-daily.timer apt-daily-upgrade.timer
Profile C is appropriate only when the administrator or an external management system assumes responsibility for all APT maintenance.
13. Command Reference
Configuration and Inspection
| Command | Description |
|---|
apt-config dump | Display effective APT configuration. |
apt-config dump | grep APT::Periodic | Display periodic update configuration. |
cat /etc/apt/apt.conf.d/20auto-upgrades | Display the standard automatic upgrade configuration. |
systemctl cat apt-daily-upgrade.service | Display the upgrade service definition. |
systemctl cat apt-daily-upgrade.timer | Display the upgrade timer definition. |
dpkg -l unattended-upgrades | Check whether unattended-upgrades is installed. |
Disabling Automatic Upgrades
| Command | Description |
|---|
sudo systemctl disable --now apt-daily-upgrade.timer | Disable scheduled automatic upgrades. |
sudo systemctl disable --now apt-daily.timer | Disable scheduled package list updates. |
sudo systemctl mask apt-daily-upgrade.service | Prevent systemd activation of the upgrade service. |
Re-enabling Automatic Upgrades
| Command | Description |
|---|
sudo dpkg-reconfigure unattended-upgrades | Reconfigure unattended upgrades. |
sudo systemctl unmask apt-daily-upgrade.service | Remove service masking. |
sudo systemctl enable --now apt-daily.timer | Enable automatic package list updates. |
sudo systemctl enable --now apt-daily-upgrade.timer | Enable scheduled automatic upgrades. |
Status and Troubleshooting
| Command | Description |
|---|
systemctl list-timers --all | Display systemd timers. |
systemctl is-enabled apt-daily-upgrade.timer | Check whether the upgrade timer is enabled. |
systemctl is-active apt-daily-upgrade.timer | Check whether the upgrade timer is active. |
systemctl status apt-daily-upgrade.service | Display upgrade service status. |
journalctl -u apt-daily-upgrade.service | Display upgrade service execution history. |
journalctl -fu apt-daily-upgrade.service | Monitor upgrade service messages. |
sudo dpkg --audit | Check for partially installed or inconsistent packages. |
Manual Package Maintenance
| Command | Description |
|---|
sudo apt update | Refresh package lists. |
apt list --upgradable | List available package upgrades. |
apt -s upgrade | Simulate package upgrades. |
sudo apt upgrade | Install available package upgrades. |
sudo apt full-upgrade | Upgrade packages, allowing dependency-related removals. |
sudo apt autoremove | Remove unnecessary dependencies. |
sudo apt autoclean | Remove obsolete cached package files. |
14. Important Files and Directories
| File or directory | Purpose |
|---|
/etc/apt/apt.conf.d/20auto-upgrades | Standard automatic update configuration. |
/etc/apt/apt.conf.d/50unattended-upgrades | Unattended upgrade policies and permitted package origins. |
/etc/apt/apt.conf.d/99-disable-unattended-upgrades | Custom local configuration override created in this article. |
/usr/lib/apt/apt.systemd.daily | APT periodic maintenance script. |
/var/log/unattended-upgrades/ | Unattended upgrade logs. |
/var/log/apt/history.log | APT package transaction history. |
/var/log/apt/term.log | APT package installation output. |
/var/log/dpkg.log | Package installation and removal history. |
/var/lib/apt/periodic/ | Periodic APT activity timestamps. |
/var/run/reboot-required | Indicates that a reboot is required. |
Conclusion
Disabling unattended upgrades on Ubuntu requires understanding the distinction between systemd timers, systemd services, and APT configuration.
Simply disabling apt-daily-upgrade.service is not sufficient because it is normally a static service activated by a timer.
The recommended approach is to:
Disable unattended package installation through a local APT configuration override.
Disable apt-daily-upgrade.timer.
Keep apt-daily.timer enabled if automatic package list updates are desired.
Perform package upgrades manually during scheduled maintenance windows.
Regularly monitor available security updates.
Security consideration: Disabling unattended upgrades transfers responsibility for installing security patches to the system administrator. A regular patch management schedule and monitoring for critical vulnerabilities are essential.
Category: Linux System Administration
Tags: Ubuntu, Ubuntu Server, Linux, APT, systemd, unattended-upgrades, Security, Patch Management, Production Servers
Applicability: Ubuntu Server using systemd and APT's standard periodic maintenance mechanism, including Ubuntu 22.04 and 24.04 LTS. Administrators should inspect their installed unit definitions and effective configuration before applying changes to other releases.