How to Enable Automatic Security Updates on Ubuntu & Debian

Unpatched software is one of the most common ways servers get compromised. The unattended-upgrades package automatically installs security patches as soon as they're published, without requiring you to log in and run apt upgrade manually.

Prerequisites

  • Ubuntu or Debian VPS
  • Root or sudo access

Step 1 — Install the Package

sudo apt update
sudo apt install unattended-upgrades apt-listchanges -y

Step 2 — Enable It

sudo dpkg-reconfigure --priority=low unattended-upgrades

Select Yes when prompted.

Step 3 — Review the Configuration

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

Confirm the security repository line is uncommented, for example on Ubuntu:

"${distro_id}:${distro_codename}-security";

Step 4 — Enable Automatic Reboots (Optional)

Some kernel updates require a reboot to take effect. To automate this at a low-traffic time:

Unattended-Upgrade::Automatic-Reboot "true";
Unattended-Upgrade::Automatic-Reboot-Time "03:00";

Only enable automatic reboots on servers where a scheduled restart won't disrupt production traffic without warning.

Step 5 — Verify Updates Are Applied

sudo cat /etc/apt/apt.conf.d/20auto-upgrades

You should see:

APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "1";

Step 6 — Test a Dry Run

sudo unattended-upgrade --dry-run --debug

Step 7 — Monitor the Logs

sudo cat /var/log/unattended-upgrades/unattended-upgrades.log

Common Errors

Updates aren't being applied — verify the systemd timer is active: systemctl status apt-daily-upgrade.timer.

A critical service didn't restart after a library update — some packages require a manual service restart even after being patched; check needrestart for a list.

Best Practices

  • Apply automatic updates only for the security repository, not full-upgrade, on production servers where controlled testing matters
  • Install needrestart to be notified when a service needs restarting after a patch
  • Keep a recent backup before enabling automatic reboots

FAQ

Will this update all packages, or just security patches?
By default, only the security repository is enabled — feature updates from the regular repository still require manual apt upgrade.

Is it safe to enable on a production server?
Yes, for security-only patches this is widely considered a best practice; just monitor logs and keep backups current.

Related Articles

  • VPS Security Checklist for Beginners
  • How to Update and Upgrade an Ubuntu/Debian VPS
  • How to Set Up Automated VPS Backups
  • unattended-upgrades, automatic updates, security patches, ubuntu, debian
  • 0 Utilisateurs l'ont trouvée utile
Cette réponse était-elle pertinente?

Articles connexes

SSH Hardening: Change the Port, Disable Root Login & Use SSH Keys (Ubuntu & Debian)

SSH is the front door to your VPS — and by default it listens on a well-known port, often...

How to Install and Configure Fail2Ban on Ubuntu & Debian (Complete Guide)

Fail2Ban monitors your server's log files and automatically blocks (bans) IP addresses that show...

How to Configure UFW Firewall on a Linux VPS (Ubuntu & Debian)

UFW (Uncomplicated Firewall) is the standard firewall front-end on Ubuntu and Debian. A correctly...

How to Enable Two-Factor Authentication (2FA) for SSH on a Linux VPS

Two-Factor Authentication (2FA) adds a second layer of protection to SSH: even if your password...

VPS Security Checklist for Beginners: 12 Essential Steps

Every new VPS is deployed with default settings that are convenient but not secure. This...