Why This Matters
It is critical to keep a server updated with the latest security patches. Without timely updates, your server remains vulnerable to known security exploits that attackers actively scan for and exploit. Unless you plan on checking your server daily, you need:- Automatic updates for critical security patches
- Email alerts for pending non-critical updates
- Every update carries some risk of breaking functionality
- Critical security patches should be applied immediately
- Non-critical updates can wait for manual review
Debian Based Systems
Your server must be able to send emails for notifications to work. See the Gmail/Exim4 configuration guide if you haven’t set up email yet.
How It Works
On Debian systems, we’ll use:- unattended-upgrades - Automatically applies system updates you specify (critical security patches)
- apt-listchanges - Shows details about package changes before installation
- apticron - Sends email notifications for pending package updates
Installation
Configure unattended-upgrades
Instead of modifying the default configuration files (which may be overwritten during updates), create a new file:Create
/etc/apt/apt.conf.d/51myunattended-upgrades with this content:Test the configuration
Run a dry-run to verify your configuration:If there are no errors, the configuration is correct. To run it immediately:
Configure apt-listchanges
Configure apt-listchanges to your preferences:Follow the prompts to set your email and notification preferences.
Understanding the Configuration
APT::Periodic Options
These control how often automated tasks run:| Option | Value | Description |
|---|---|---|
Update-Package-Lists | 1 | Update package lists daily |
Download-Upgradeable-Packages | 1 | Download updates daily |
AutocleanInterval | 7 | Clean old packages weekly |
Unattended-Upgrade | 1 | Apply upgrades daily |
Unattended-Upgrade Options
| Option | Setting | Description |
|---|---|---|
Origins-Pattern | Debian stable, stable-updates, security | Which repositories to auto-upgrade from |
Package-Blacklist | Empty | Packages to never auto-upgrade |
Mail | root | Email address for notifications |
MailOnlyOnError | false | Send email for all upgrades, not just errors |
Automatic-Reboot | true | Automatically reboot if kernel updated |
Automatic-Reboot-WithUsers | true | Reboot even with users logged in |
Blacklisting Packages
To prevent specific packages from being automatically upgraded, add them to the blacklist:Monitoring
Check Upgrade Logs
View what unattended-upgrades has done:Check Last Run
Check for Pending Updates
What This Does
With automatic updates configured:Security Patches
Critical security updates are applied automatically within 24 hours
Email Notifications
You receive emails about all updates and system changes
Stable Updates
Only tested, stable updates are applied automatically
System Cleanup
Old packages are automatically cleaned up weekly
Troubleshooting
Not Receiving Emails
-
Verify your mail configuration:
-
Check mail logs:
Updates Not Running
-
Check the systemd timer:
-
Manually trigger an update:
Checking What Will Be Upgraded
The configuration files in
/etc/apt/apt.conf.d/ are processed in numerical order. Our custom file 51myunattended-upgrades overrides settings from the default 50unattended-upgrades.