Most break-ins on small servers use security holes that already have a fix. Automatic security updates close that gap within a day of a patch being released, even when you are busy.
Update everything once by hand
Start from a fully patched system.
sudo apt update && sudo apt upgrade -y # Ubuntu / Debian
sudo dnf upgrade -y # AlmaLinux / Rocky LinuxUbuntu and Debian: unattended-upgrades
1. Install and switch it on
Ubuntu usually has it already. Debian minimal images may not.
sudo apt install -y unattended-upgrades apt-listchanges
sudo dpkg-reconfigure -plow unattended-upgradesAnswer Yes. This writes /etc/apt/apt.conf.d/20auto-upgrades, which should contain:
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "1";2. Decide about reboots
Kernel and core library updates only take effect after a reboot. Open /etc/apt/apt.conf.d/50unattended-upgrades and set these lines if you want the server to reboot itself at a quiet hour when needed:
Unattended-Upgrade::Automatic-Reboot "true";
Unattended-Upgrade::Automatic-Reboot-Time "04:00";Leave them at false if an unplanned reboot would hurt, and reboot by hand when /var/run/reboot-required exists.
3. Test it
sudo unattended-upgrade --dry-run --debugLogs are kept in /var/log/unattended-upgrades/.
AlmaLinux and Rocky Linux: dnf-automatic
1. Install
sudo dnf install -y dnf-automatic2. Configure security-only updates
Edit /etc/dnf/automatic.conf and set these values in the [commands] section:
[commands]
upgrade_type = security
download_updates = yes
apply_updates = yesUse upgrade_type = default if you prefer all updates, not only security fixes.
3. Enable the timer
sudo systemctl enable --now dnf-automatic.timer
systemctl list-timers 'dnf-automatic*'To see whether a reboot is needed after updates, run:
sudo dnf needs-restarting -rTip: Automatic updates are not a backup. Keep copies of your data off the server so a bad update is easy to recover from. See Back up your Linux VPS.
Troubleshooting
- Nothing seems to install: on Debian/Ubuntu check
20auto-upgradescontains both lines set to"1". On AlmaLinux/Rocky make sureapply_updates = yesand the timer is active. - A held package is never updated:
apt-mark showholdlists packages pinned by hand. Remove the hold withsudo apt-mark unhold <package>if it is no longer needed. - dpkg was interrupted: run
sudo dpkg --configure -a, thensudo apt -f install.
