The short answer
Enable the unattended-upgrades package and configure it to apply only critical security updates. This ensures your server receives vital patches automatically while you sleep.
Why automatic security updates matter
When patches are applied manually, there is always a window of time between the release of a security update and the moment an administrator installs it. During that interval, known vulnerabilities remain exploitable, and attackers can target unpatched services. Small businesses often lack dedicated staff to monitor advisories continuously, so delays are common. Each missed update increases the attack surface and can lead to compromise of data, service downtime, or reputational damage.
The Ubuntu package unattended-upgrades automates the installation of security updates as soon as they become available. It runs in the background, checks the repository for new security patches, and applies them without human intervention. This reduces the exposure period dramatically, ensuring that critical fixes are in place promptly. By using this tool, administrators can maintain a more consistent security posture while freeing time for other tasks.
- Installs only security‑related packages
- Runs daily by default
- Logs actions to
/var/log/unattended-upgrades - Can be configured to reboot automatically if required
sudo apt-get update && sudo apt-get install -y unattended-upgrades && sudo dpkg-reconfigure --priority=low unattended-upgradesAfter enabling the service, verify that /etc/apt/apt.conf.d/20auto-upgrades contains APT::Periodic::Unattended-Upgrade "1";. Check the log file periodically to confirm that updates are being applied without errors.
Check your current update status
First, confirm that the unattended-upgrades package is present on your Ubuntu system. Use the package manager to query its installation status. If the package is missing, you can install it from the official repositories. Knowing whether the tool is installed helps you decide if you need to add it before checking its configuration. This step is safe and does not modify any files; it only reads the package database.
Next, verify that unattended-upgrades is enabled and actively scheduled. The service runs as a systemd timer, so you can query its status to see if the timer is loaded and active. Checking the timer ensures that automatic security updates will be applied without manual intervention. If the timer is disabled, you can enable it later, but first you should understand the current state.
- Run
apt list --installed unattended-upgradesto see if the package is installed. - Use
systemctl status unattended-upgrades.serviceto view the service status. - Check the timer with
systemctl list-timers --all | grep unattended-upgrades.
apt list --installed unattended-upgrades
systemctl status unattended-upgrades.service
systemctl list-timers --all | grep unattended-upgradesLook for a line indicating the package is installed, and for the service status to show "active (running)". The timer output should display a next run time, confirming that automatic updates are scheduled.
Install and configure the package
First, install the unattended‑upgrades package using the system package manager. The package provides a background daemon that can automatically download and install security updates without manual intervention. Run the install command and then ensure the service is enabled so it starts on boot. This step prepares the server to handle updates safely and keeps the system patched against known vulnerabilities.
Next, edit the configuration file to limit updates to security patches only. Open /etc/apt/apt.conf.d/50unattended-upgrades and uncomment the line that includes the ${distro_id}:${distro_codename}-security repository. Save the file, then verify the schedule in /etc/apt/apt.conf.d/20auto-upgrades to run daily. This configuration ensures only critical security updates are applied automatically, reducing the risk of unintended changes.
- Install the package with
apt install unattended-upgrades. - Enable the service:
systemctl enable --now unattended-upgrades. - Edit
/etc/apt/apt.conf.d/50unattended-upgradesto enable security repo. - Set daily run in
/etc/apt/apt.conf.d/20auto-upgrades. - Test the configuration with
unattended-upgrade --dry-run.
apt update && apt install -y unattended-upgrades
systemctl enable --now unattended-upgrades
sed -i 's|// \${distro_id}:\${distro_codename}-security;|\${distro_id}:\${distro_codename}-security;|' /etc/apt/apt.conf.d/50unattended-upgrades
cat <<EOF > /etc/apt/apt.conf.d/20auto-upgrades
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "1";
EOFAfter these steps, check the log file at /var/log/unattended-upgrades/unattended-upgrades.log to confirm that security updates are being downloaded and installed as scheduled.
Limit updates to security patches
On Ubuntu, the unattended‑upgrade service can be tuned to install only security updates. By editing /etc/apt/apt.conf.d/50unattended-upgrades you can enable the Unattended-Upgrade::Allowed-Origins block for security releases, and set Unattended-Upgrade::Automatic-Reboot to false to avoid unexpected reboots. This keeps the system stable while still applying critical patches. It is a good idea to test the configuration on a staging server before deploying to production, and to keep a recent snapshot or backup in case a package causes an issue.
After enabling security‑only updates, monitor the /var/log/unattended-upgrades/unattended-upgrades.log file. Look for entries that show packages being installed and confirm that only *-security packages appear. If you see non‑security packages, revisit the Allowed-Origins list. Also check that the log ends with “All upgrades installed” and that no errors were reported. This confirms the policy is working as intended.
# Example: enable security updates only
sudo nano /etc/apt/apt.conf.d/50unattended-upgrades
# Ensure the following lines are present:
# Unattended-Upgrade::Allowed-Origins {
# "${distro_id}:${distro_codename}-security";
# }Verify that /var/log/unattended-upgrades/unattended-upgrades.log lists only security packages and that no errors appear.
Pitfalls to avoid
Enabling automatic updates for all packages can install new features, bug fixes, or changes that affect your application’s behaviour. A feature update to a library that your site depends on may break a plugin or cause a compatibility issue. Always test updates in a staging environment before applying them to production, and keep a recent snapshot or backup so you can revert if something fails.
Skipping the backup step before turning on automatic updates is a common mistake. Without a recent snapshot, a problematic update could leave your system in an unusable state. Even if the update process is automated, you should schedule regular snapshots or full backups. This protects you from accidental data loss, misconfigurations, or updates that introduce vulnerabilities.
Monitoring and logging
After enabling automatic security updates, verify that they are actually being installed by reviewing the system logs. Ubuntu records package management activity in /var/log/apt/history.log and /var/log/unattended-upgrades/unattended-upgrades.log. Open these files with a pager like less or grep for recent entries. Look for lines that mention "Start-Date", "Upgrade", and "End-Date" which indicate when the unattended upgrade process began and finished, and note the package names that were upgraded.
If you prefer a concise summary, you can use apt list --upgradable to see pending updates and systemctl status unattended-upgrades to check the service's recent run status. Regularly checking these logs helps you confirm that critical security patches are applied without manual intervention. It also provides an audit trail useful for compliance reporting or troubleshooting failed updates.
- Use
less /var/log/apt/history.logto scroll through recent package actions. - Search
unattended-upgrades.logfor "Packages upgraded" to see which security patches were applied. - Run
systemctl status unattended-upgradesto view the last service execution result.
less /var/log/apt/history.log
less /var/log/unattended-upgrades/unattended-upgrades.log
systemctl status unattended-upgradesIn the log output, confirm that each entry ends with an "End-Date" line and lists the security packages that were upgraded. Absence of recent entries or error messages may indicate a problem with the automatic update configuration.
Long-term maintenance
Regularly reviewing your security settings ensures that your server remains resilient against new threats. Schedule a quarterly audit of the /etc/apt/apt.conf.d/ directory, verify that Unattended-Upgrade::Allowed-Origins includes only trusted repositories, and confirm that the APT::Periodic::Unattended-Upgrade flag is set to 1. Keep a change log of any modifications so you can trace back to a configuration that may have introduced a problem. This practice helps you catch misconfigurations early and maintain a clear record for compliance and troubleshooting. Kernel updates often bring critical fixes but may also require a reboot. Use unattended-upgrades to install kernel packages automatically, but monitor the /var/run/reboot-required file after each update. If the file exists, schedule a maintenance window to reboot the system. Verify that services restart correctly with systemctl list-units --type=service --state=failed. Document the reboot schedule and notify stakeholders to avoid unexpected downtime.
- Ensure the
Unattended-Upgrade::Package-Blacklistdoes not block essential security updates. Check thatAPT::Periodic::Download-Upgradeable-Packagesis enabled. Verify that theapt-listchangespackage is installed to review changelogs before upgrades.
# Example: check if a reboot is required after an update
if [ -f /var/run/reboot-required ]; then echo "Reboot needed"; fi
# Example: view failed services after a reboot
systemctl list-units --type=service --state=failedLook for the presence of /var/run/reboot-required and any failed services listed by systemctl. If services have failed, investigate the logs in /var/log/syslog or journalctl to determine the cause.
If you would rather have engineers do this for you, see Linux server management, Windows server management or emergency malware cleanup.
Questions people ask
Will unattended-upgrades reboot my server automatically?
Unattended‑upgrades can reboot the system if a kernel or critical package requires it. By default the `Unattended-Upgrade::Automatic-Reboot` option is set to `false`. You can enable it by editing `/etc/apt/apt.conf.d/50unattended-upgrades` and setting the line to `true`.
How do I check if the last automatic update succeeded?
To see the result of the last automatic update, look at the log file `/var/log/unattended-upgrades/unattended-upgrades.log`. The file contains timestamps and a status line such as `Unattended-upgrades finished successfully` or lists any failures.
Can I exclude specific packages from automatic updates?
Yes. In `/etc/apt/apt.conf.d/50unattended-upgrades` you can add package names to the `Unattended-Upgrade::Package-Blacklist` list. Each package is written on a separate line, quoted, e.g. `"vim";`. Packages in this list will be skipped.
Does this work on Ubuntu 20.04 and 22.04?
The unattended‑upgrades package is available and works on Ubuntu 20.04 (Focal) and 22.04 (Jammy). The configuration file paths and options are the same for both releases, so the same steps apply.