Prerequisites:
- Ubuntu or Debian-based Linux system
- Root or sudo access
- Internet connection
unattended-upgrades to ensure your system receives security patches automatically.
Manual System Updates
Before setting up automatic upgrades, understand the basic update commands:Update package lists
Refresh the package index to get the latest information about available packages:This downloads package information from all configured repositories.
Upgrade installed packages
Upgrade all installed packages to their latest versions:You can also combine both commands:
Installing Unattended-Upgrades
Configuring Unattended-Upgrades
Configure unattended-upgrades to automatically install security updates.Run configuration wizard
Launch the interactive configuration tool:You’ll be presented with a series of prompts:
- Automatically download and install stable updates? - Select “Yes”
- Email address for update notifications - Enter your email (optional)
- Automatic reboot options - Choose based on your needs
Configuration File Settings
The main configuration file is located at/etc/apt/apt.conf.d/50unattended-upgrades. Here are key settings:
Update Origins
Update Origins
Specify which updates to install. The default configuration includes:This ensures only security updates are installed automatically.
Package Blacklist
Package Blacklist
Prevent specific packages from being automatically updated:Useful for packages that require manual intervention or testing.
Automatic Reboot
Automatic Reboot
Configure automatic reboots after updates:
Email Notifications
Email Notifications
Receive email notifications about updates:Set
MailOnlyOnError to false to receive notifications for all updates.Remove Unused Dependencies
Remove Unused Dependencies
Automatically remove unused packages after updates:
Enable Automatic Updates
Enable automatic updates
Create or edit the auto-update configuration file:Add the following configuration:
Configuration values explained
Update-Package-Lists "1"- Update package lists dailyUnattended-Upgrade "1"- Run unattended-upgrade dailyDownload-Upgradeable-Packages "1"- Download upgradeable packages dailyAutocleanInterval "7"- Clean package cache every 7 days
"0" to disable a feature.Testing Unattended-Upgrades
Test configuration
Test the configuration without making changes:This shows what would be updated without actually installing anything.
Monitoring Automatic Upgrades
Check update status
Check update status
View the current status of automatic updates:
View update history
View update history
Check what updates have been installed:
Check for pending updates
Check for pending updates
See what updates are available:
Service status
Service status
Check if the unattended-upgrades service is running:
Recommended Configuration
Here’s a complete recommended configuration for production servers:/etc/apt/apt.conf.d/50unattended-upgrades
/etc/apt/apt.conf.d/20auto-upgrades
Disabling Automatic Upgrades
If you need to disable automatic upgrades:Troubleshooting
Updates not installing automatically
Updates not installing automatically
Check:
- Service status:
sudo systemctl status unattended-upgrades - Configuration files:
cat /etc/apt/apt.conf.d/20auto-upgrades - Logs:
sudo tail -f /var/log/unattended-upgrades/unattended-upgrades.log - Test manually:
sudo unattended-upgrades --dry-run
Too many email notifications
Too many email notifications
Reduce notification frequency:Or disable email notifications entirely by removing or commenting out the Mail line.
Packages being updated that shouldn't be
Packages being updated that shouldn't be
Add packages to the blacklist in
/etc/apt/apt.conf.d/50unattended-upgrades:System rebooting unexpectedly
System rebooting unexpectedly
Disable automatic reboots:Then restart the service:
Disk space issues
Disk space issues
Automatic updates can fill up disk space. Enable automatic cleanup:Manually clean up:
Best Practices
Security Updates Only
Configure to install only security updates automatically. Regular updates can be done manually after testing.
Email Notifications
Set up email notifications to monitor what updates are being installed.
Package Blacklist
Blacklist critical packages that require manual testing before updates.
Regular Monitoring
Review logs weekly to ensure updates are installing correctly.
Backup Before Updates
Ensure you have backups before enabling automatic updates on production systems.
Test Environment
Test automatic updates in a staging environment before enabling on production.
Quick Reference
Important: While automatic updates improve security, always test updates in a staging environment first, especially for production systems. Consider blacklisting critical packages that require manual testing.
