{"id":1065,"date":"2026-09-06T22:07:47","date_gmt":"2026-09-06T22:07:47","guid":{"rendered":"https:\/\/virtualserversvps.com\/blog\/?p=1065"},"modified":"2026-09-06T22:07:47","modified_gmt":"2026-09-06T22:07:47","slug":"automate-vps-security-patching-unattended-upgrades","status":"publish","type":"post","link":"https:\/\/virtualserversvps.com\/blog\/automate-vps-security-patching-unattended-upgrades\/","title":{"rendered":"How to Automate VPS Security Patching with Unattended Upgrades"},"content":{"rendered":"<p class=\"wp-block-paragraph\">Security patches arrive daily. If you patch manually, you are always behind. Unattended-upgrades is the built-in mechanism on Debian and Ubuntu that automatically installs security updates without human intervention. Configured correctly, it keeps your <a href=\"https:\/\/virtualserversvps.com\/\">VPS<\/a> patched within hours of a CVE being fixed while avoiding the risk of a broken update taking down your production services. This guide covers setup, fine-tuning, monitoring, and the edge cases that trip people up.<\/p>\n<h2 class=\"wp-block-heading\">How Unattended Upgrades Work<\/h2>\n<p class=\"wp-block-paragraph\">The unattended-upgrades package runs as a systemd timer (or cron job on older systems). It checks the apt package cache for available updates, filters them by origin (security, stable, backports), downloads the matching packages, and installs them. It can also automatically reboot the server if a kernel update was installed and email you a summary of what it did.<\/p>\n<p class=\"wp-block-paragraph\">By default, Ubuntu Server and Debian install the package but only enable it for security updates. This is the correct starting point \u2014 security patches are tested and unlikely to break anything.<\/p>\n<h2 class=\"wp-block-heading\">Step 1: Install and Enable<\/h2>\n<pre class=\"wp-block-code\"><code># Install the package (usually already present)\nsudo apt install unattended-upgrades apt-listchanges -y\n\n# Enable it for the first time\nsudo dpkg-reconfigure -plow unattended-upgrades\n# Select \"Yes\" when prompted<\/code><\/pre>\n<p class=\"wp-block-paragraph\">Verify the timer is active:<\/p>\n<pre class=\"wp-block-code\"><code>sudo systemctl status apt-daily-upgrade.timer\n\n# Or check the timer schedule\nsudo systemctl list-timers apt-daily-upgrade.timer<\/code><\/pre>\n<h2 class=\"wp-block-heading\">Step 2: Configure Update Sources<\/h2>\n<p class=\"wp-block-paragraph\">Edit <code>\/etc\/apt\/apt.conf.d\/50unattended-upgrades<\/code>. The critical section is the <code>Unattended-Upgrade::Allowed-Origins<\/code> block. A secure configuration for a production VPS:<\/p>\n<pre class=\"wp-block-code\"><code>Unattended-Upgrade::Allowed-Origins {\n    \"${distro_id}:${distro_codename}-security\";\n    \"${distro_id}ESMApps:${distro_codename}-apps-security\";\n    \"${distro_id}ESM:${distro_codename}-infra-security\";\n};<\/code><\/pre>\n<p class=\"wp-block-paragraph\">This limits automatic updates to security patches only. Do not add <code>${distro_codename}-updates<\/code> unless you have a staging environment that tests updates before they reach production. A non-security package update can break your application stack.<\/p>\n<h2 class=\"wp-block-heading\">Step 3: Blacklist Packages That Should Never Auto-Update<\/h2>\n<p class=\"wp-block-paragraph\">Some packages are too risky to update automatically. Add a blacklist in the same configuration file:<\/p>\n<pre class=\"wp-block-code\"><code>Unattended-Upgrade::Package-Blacklist {\n    \"mysql-server\";\n    \"mysql-server-8.0\";\n    \"postgresql\";\n    \"redis-server\";\n    \"docker-ce\";\n    \"docker-ce-cli\";\n    \"containerd.io\";\n};<\/code><\/pre>\n<p class=\"wp-block-paragraph\">Database servers, container runtimes, and custom-compiled packages should be updated manually during a maintenance window. A database major version bump applied automatically at 3 AM is a fast path to an outage.<\/p>\n<h2 class=\"wp-block-heading\">Step 4: Configure Automatic Reboots<\/h2>\n<p class=\"wp-block-paragraph\">Kernel security updates take effect only after a reboot. Unattended-upgrades can handle this automatically:<\/p>\n<pre class=\"wp-block-code\"><code>Unattended-Upgrade::Automatic-Reboot \"true\";\nUnattended-Upgrade::Automatic-Reboot-Time \"04:00\";\nUnattended-Upgrade::Automatic-Reboot-WithUsers \"false\";\nUnattended-Upgrade::Remove-Unused-Kernel-Packages \"true\";\nUnattended-Upgrade::Remove-New-Unused-Dependencies \"true\";<\/code><\/pre>\n<p class=\"wp-block-paragraph\">The <code>Automatic-Reboot-WithUsers<\/code> setting is important: when set to <code>false<\/code>, the server will not reboot if a user is logged in via SSH. This prevents interrupting an active admin session. Set it to <code>true<\/code> only if you are confident nobody will be logged in at 4 AM.<\/p>\n<p class=\"wp-block-paragraph\">If you run a service that needs a graceful shutdown before reboot, add a pre-reboot hook:<\/p>\n<pre class=\"wp-block-code\"><code># \/etc\/kernel\/postinst.d\/zzz-pre-reboot\n#!\/bin\/bash\n# This script runs before the automatic reboot\nsystemctl stop my-custom-app\nsleep 5<\/code><\/pre>\n<h2 class=\"wp-block-heading\">Step 5: Email Notifications<\/h2>\n<p class=\"wp-block-paragraph\">You need to know what unattended-upgrades is doing. Configure email reports:<\/p>\n<pre class=\"wp-block-code\"><code>Unattended-Upgrade::Mail \"admin@example.com\";\nUnattended-Upgrade::MailReport \"on-change\";\nUnattended-Upgrade::SyslogEnable \"true\";\nUnattended-Upgrade::SyslogFacility \"daemon\";<\/code><\/pre>\n<p class=\"wp-block-paragraph\">The <code>on-change<\/code> setting sends an email only when packages were actually installed, not every day. For email delivery, your VPS needs a functioning MTA. A minimal setup with msmtp or postfix relaying through an external SMTP server works well:<\/p>\n<pre class=\"wp-block-code\"><code># Install a lightweight mail sender\nsudo apt install msmtp msmtp-mta -y\n\n# Configure \/etc\/msmtprc with your SMTP credentials\n# Then test\n echo \"Test from unattended-upgrades\" | mail -s \"Test\" admin@example.com<\/code><\/pre>\n<h2 class=\"wp-block-heading\">Step 6: Dry Run and Verify<\/h2>\n<p class=\"wp-block-paragraph\">Before letting unattended-upgrades run on its own, simulate what it would do:<\/p>\n<pre class=\"wp-block-code\"><code># Dry run \u2014 shows what would be installed without doing it\nsudo unattended-upgrade --dry-run --debug\n\n# Check the log for any issues\nsudo tail -f \/var\/log\/unattended-upgrades\/unattended-upgrades.log<\/code><\/pre>\n<p class=\"wp-block-paragraph\">The dry run output lists every package that would be upgraded. Look for anything surprising \u2014 a kernel update on a system that should not reboot, or a database package that slipped past the blacklist.<\/p>\n<h2 class=\"wp-block-heading\">Production Hardening Checklist<\/h2>\n<ul class=\"wp-block-list\">\n<li><strong>Stagger the update time:<\/strong> Edit <code>\/lib\/systemd\/system\/apt-daily-upgrade.timer<\/code> override to randomize the update window. This prevents every VPS in a fleet from updating simultaneously.<\/li>\n<li><strong>Monitor with Netdata or Prometheus:<\/strong> Track the <code>unattended-upgrades<\/code> log for errors. A failed update that goes unnoticed for weeks is worse than no update at all.<\/li>\n<li><strong>Test on a staging VPS first:<\/strong> If you run a custom application stack, mirror the configuration on a staging VPS and let unattended-upgrades run there for a week before enabling it on production.<\/li>\n<li><strong>Keep a rollback plan:<\/strong> Unattended-upgrades does not create snapshots. If an update breaks your application, you need a way to roll back. Consider VPS snapshots from your provider or <code>apt-btrfs-snapshot<\/code> on Btrfs filesystems.<\/li>\n<li><strong>Check <code>\/var\/run\/reboot-required<\/code>:<\/strong> After a kernel update, this file is created. Include a check for it in your monitoring.<\/li>\n<\/ul>\n<h2 class=\"wp-block-heading\">Troubleshooting Common Issues<\/h2>\n<ul class=\"wp-block-list\">\n<li><strong>Updates not running:<\/strong> Check the timer: <code>sudo systemctl list-timers apt-daily-upgrade.timer<\/code>. If the timer is inactive, enable it: <code>sudo systemctl enable --now apt-daily-upgrade.timer<\/code>.<\/li>\n<li><strong>&#8220;dpkg was interrupted&#8221; errors:<\/strong> A previous update was interrupted. Run <code>sudo dpkg --configure -a<\/code> to fix the package state, then <code>sudo unattended-upgrade -d<\/code> to retry.<\/li>\n<li><strong>Disk space exhaustion:<\/strong> Unattended-upgrades downloads packages to <code>\/var\/cache\/apt\/archives\/<\/code>. If disk space is tight, add <code>Unattended-Upgrade::Remove-Unused-Dependencies \"true\";<\/code> to clean up after each run.<\/li>\n<li><strong>Custom repositories:<\/strong> If you added third-party repositories (Docker, HashiCorp, etc.), their updates are not covered by default. Add their origin lines explicitly if you want them auto-updated \u2014 but this is generally not recommended for production.<\/li>\n<\/ul>\n<p class=\"wp-block-paragraph\">Unattended-upgrades is the simplest security automation you can deploy on a VPS. It eliminates the gap between CVE disclosure and patch application, and it does so with a conservative, Debian-tested approach. For more on securing your VPS, visit our <a href=\"https:\/\/virtualserversvps.com\/\">VPS hosting guides<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Security patches arrive daily. If you patch manually, you are always behind. Unattended-upgrades is the built-in mechanism on Debian and Ubuntu that automatically installs security updates without human intervention. Configured&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":0,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-1065","post","type-post","status-publish","format-standard","hentry","category-security-compliance"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.1 (Yoast SEO v26.1) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to Automate VPS Security Patching with Unattended Upgrades - Virtual Servers VPS Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/virtualserversvps.com\/blog\/automate-vps-security-patching-unattended-upgrades\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Automate VPS Security Patching with Unattended Upgrades\" \/>\n<meta property=\"og:description\" content=\"How to Automate VPS Security Patching with Unattended Upgrades\" \/>\n<meta property=\"og:url\" content=\"https:\/\/virtualserversvps.com\/blog\/automate-vps-security-patching-unattended-upgrades\/\" \/>\n<meta property=\"og:site_name\" content=\"Virtual Servers VPS Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-09-06T22:07:47+00:00\" \/>\n<meta name=\"author\" content=\"Virtual-Servers-Vps-Editor\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Virtual-Servers-Vps-Editor\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/automate-vps-security-patching-unattended-upgrades\/\",\"url\":\"https:\/\/virtualserversvps.com\/blog\/automate-vps-security-patching-unattended-upgrades\/\",\"name\":\"How to Automate VPS Security Patching with Unattended Upgrades - Virtual Servers VPS Blog\",\"isPartOf\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#website\"},\"datePublished\":\"2026-09-06T22:07:47+00:00\",\"author\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0\"},\"breadcrumb\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/automate-vps-security-patching-unattended-upgrades\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/virtualserversvps.com\/blog\/automate-vps-security-patching-unattended-upgrades\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/automate-vps-security-patching-unattended-upgrades\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/virtualserversvps.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Automate VPS Security Patching with Unattended Upgrades\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#website\",\"url\":\"https:\/\/virtualserversvps.com\/blog\/\",\"name\":\"Virtual Servers VPS Blog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/virtualserversvps.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0\",\"name\":\"Virtual-Servers-Vps-Editor\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/d820b15f1cd028e97610d9adf536df7be5cb6423869967037d468d5355fa003f?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/d820b15f1cd028e97610d9adf536df7be5cb6423869967037d468d5355fa003f?s=96&d=mm&r=g\",\"caption\":\"Virtual-Servers-Vps-Editor\"},\"sameAs\":[\"https:\/\/virtualserversvps.com\/blog\"],\"url\":\"https:\/\/virtualserversvps.com\/blog\/author\/virtualserversvps\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"How to Automate VPS Security Patching with Unattended Upgrades - Virtual Servers VPS Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/virtualserversvps.com\/blog\/automate-vps-security-patching-unattended-upgrades\/","og_locale":"en_US","og_type":"article","og_title":"How to Automate VPS Security Patching with Unattended Upgrades","og_description":"How to Automate VPS Security Patching with Unattended Upgrades","og_url":"https:\/\/virtualserversvps.com\/blog\/automate-vps-security-patching-unattended-upgrades\/","og_site_name":"Virtual Servers VPS Blog","article_published_time":"2026-09-06T22:07:47+00:00","author":"Virtual-Servers-Vps-Editor","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Virtual-Servers-Vps-Editor","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/virtualserversvps.com\/blog\/automate-vps-security-patching-unattended-upgrades\/","url":"https:\/\/virtualserversvps.com\/blog\/automate-vps-security-patching-unattended-upgrades\/","name":"How to Automate VPS Security Patching with Unattended Upgrades - Virtual Servers VPS Blog","isPartOf":{"@id":"https:\/\/virtualserversvps.com\/blog\/#website"},"datePublished":"2026-09-06T22:07:47+00:00","author":{"@id":"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0"},"breadcrumb":{"@id":"https:\/\/virtualserversvps.com\/blog\/automate-vps-security-patching-unattended-upgrades\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/virtualserversvps.com\/blog\/automate-vps-security-patching-unattended-upgrades\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/virtualserversvps.com\/blog\/automate-vps-security-patching-unattended-upgrades\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/virtualserversvps.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to Automate VPS Security Patching with Unattended Upgrades"}]},{"@type":"WebSite","@id":"https:\/\/virtualserversvps.com\/blog\/#website","url":"https:\/\/virtualserversvps.com\/blog\/","name":"Virtual Servers VPS Blog","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/virtualserversvps.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0","name":"Virtual-Servers-Vps-Editor","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/d820b15f1cd028e97610d9adf536df7be5cb6423869967037d468d5355fa003f?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d820b15f1cd028e97610d9adf536df7be5cb6423869967037d468d5355fa003f?s=96&d=mm&r=g","caption":"Virtual-Servers-Vps-Editor"},"sameAs":["https:\/\/virtualserversvps.com\/blog"],"url":"https:\/\/virtualserversvps.com\/blog\/author\/virtualserversvps\/"}]}},"_links":{"self":[{"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts\/1065","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/comments?post=1065"}],"version-history":[{"count":1,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts\/1065\/revisions"}],"predecessor-version":[{"id":1067,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts\/1065\/revisions\/1067"}],"wp:attachment":[{"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/media?parent=1065"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/categories?post=1065"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/tags?post=1065"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}