Many break-ins use known bugs that already have a fix. Automatic security updates install those fixes for you. The trade-off is that some updates, mainly the kernel, need a reboot to take effect. If you are logged in as root, leave out sudo.
sudo apt update
sudo apt install -y unattended-upgrades
sudo dpkg-reconfigure -plow unattended-upgrades
Answer "Yes". Security updates are now installed automatically. Check the setup with a dry run:
sudo unattended-upgrade --dry-run --debug | tail -20
ls /var/log/unattended-upgrades/Some updates are only active after a reboot. See whether one is pending:
[ -f /var/run/reboot-required ] && echo "reboot needed" || echo "no reboot needed"
If the file exists, reboot when it suits you. To let the server reboot itself at a quiet hour, edit /etc/apt/apt.conf.d/50unattended-upgrades, find these two lines, remove the leading // and set (the time is the server's own clock, often UTC):
Unattended-Upgrade::Automatic-Reboot "true";
Unattended-Upgrade::Automatic-Reboot-Time "04:00";
Only do this if a short restart at that time is acceptable for what the server runs, and make sure your services start by themselves after boot (systemctl enable, restart: unless-stopped for containers).
sudo dnf install -y dnf-automatic
sudo sed -i 's/^apply_updates = .*/apply_updates = yes/' /etc/dnf/automatic.conf
sudo systemctl enable --now dnf-automatic.timer
Check the timer with systemctl list-timers | grep dnf. To see whether a reboot is pending: sudo dnf needs-restarting -r (package yum-utils). To install only security updates, set upgrade_type = security in the same file.
How do I turn on automatic security updates on Ubuntu or Debian?
Install unattended-upgrades and run sudo dpkg-reconfigure -plow unattended-upgrades, answering Yes.
Do automatic updates reboot the server?
Not by default. Some updates need a reboot to take effect; check /var/run/reboot-required, or set an automatic reboot time if a short restart is acceptable.
What about AlmaLinux or Rocky?
Install dnf-automatic, set apply_updates = yes in /etc/dnf/automatic.conf and enable dnf-automatic.timer.
Do automatic updates replace backups?
No. Keep your own backups; updates also do not cover Docker images or your own applications.