
Most server compromises exploit vulnerabilities that already have a fix. Automatic security updates close that gap without you having to log in every day. This guide shows how to enable automatic updates on Ubuntu and Debian with unattended-upgrades, and on Rocky Linux, AlmaLinux, RHEL and Fedora with dnf-automatic, how to control what is updated, handle reboots, get email reports, and check that it is working.
Quick answer
# Ubuntu / Debian
sudo apt install unattended-upgrades
sudo dpkg-reconfigure -plow unattended-upgrades
# Rocky / AlmaLinux / RHEL
sudo dnf install dnf-automatic
sudo sed -i 's/^apply_updates.*/apply_updates = yes/' /etc/dnf/automatic.conf
sudo systemctl enable --now dnf-automatic.timer
Should you automate all updates?
Automatically installing security updates is the right default for almost every server. Automatically installing all updates is riskier on production systems, because a new version of a database or web server can change behaviour. A common approach is: security updates automatic, everything else applied manually during maintenance windows, with backups or snapshots in place.
Ubuntu and Debian: unattended-upgrades
Step 1: Install and enable
sudo apt update
sudo apt install unattended-upgrades
sudo dpkg-reconfigure -plow unattended-upgrades
Answer Yes to enable automatic updates. Ubuntu Server usually has the package installed and enabled already; this step makes sure. It creates /etc/apt/apt.conf.d/20auto-upgrades:
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "1";
"1" means run every day.
Step 2: Choose what gets updated
Edit /etc/apt/apt.conf.d/50unattended-upgrades. The Allowed-Origins (Ubuntu) or Origins-Pattern (Debian) section lists which repositories are upgraded. By default only security updates (and Ubuntu Pro ESM if attached) are enabled:
Unattended-Upgrade::Allowed-Origins {
"${distro_id}:${distro_codename}";
"${distro_id}:${distro_codename}-security";
"${distro_id}ESMApps:${distro_codename}-apps-security";
"${distro_id}ESM:${distro_codename}-infra-security";
// "${distro_id}:${distro_codename}-updates";
};
Uncomment the -updates line to install all regular updates too. Exclude specific packages with:
Unattended-Upgrade::Package-Blacklist {
"mysql-server";
"nginx";
};
Step 3: Reboots, cleanup and email
In the same file:
Unattended-Upgrade::Remove-Unused-Kernel-Packages "true";
Unattended-Upgrade::Remove-Unused-Dependencies "true";
Unattended-Upgrade::Automatic-Reboot "true";
Unattended-Upgrade::Automatic-Reboot-Time "03:30";
Unattended-Upgrade::Mail "admin@example.com";
Unattended-Upgrade::MailReport "on-change";
Kernel updates only take effect after a reboot. If automatic reboots are not acceptable, leave them off and watch for /var/run/reboot-required; on Ubuntu, Canonical Livepatch (part of Ubuntu Pro) applies many kernel security fixes without rebooting. Email reports need a working mail setup such as mailutils with a relay.
Step 4: Test and check logs
sudo unattended-upgrade --dry-run --debug
cat /var/log/unattended-upgrades/unattended-upgrades.log
systemctl list-timers apt-daily*
The dry run shows which packages would be upgraded without changing anything.
Rocky Linux, AlmaLinux and RHEL: dnf-automatic
Step 1: Install
sudo dnf install dnf-automatic
Step 2: Configure
Edit /etc/dnf/automatic.conf:
[commands]
upgrade_type = security
download_updates = yes
apply_updates = yes
reboot = when-needed
reboot_command = "shutdown -r +5 'Rebooting after applying package updates'"
[emitters]
emit_via = stdio
upgrade_type = securityinstalls only security updates; usedefaultfor all updates.apply_updates = yesinstalls them; withno, updates are only downloaded.reboot = when-neededreboots only when an update requires it. Leave it atneverif you prefer to reboot manually.- Set
emit_via = emailand the[email]section to receive reports.
Step 3: Enable the timer
sudo systemctl enable --now dnf-automatic.timer
systemctl list-timers dnf-automatic*
Check results with journalctl -u dnf-automatic.
Fedora (DNF5)
Fedora 41 and later use DNF5, where automatic updates come from the dnf5-plugin-automatic package. The configuration options are similar; copy the default file from /usr/share/dnf5/dnf5-plugins/automatic.conf to /etc/dnf/automatic.conf, edit it, and enable dnf5-automatic.timer.
Best practices
- Take automatic backups or snapshots so you can roll back a bad update.
- Pin or exclude packages you upgrade deliberately, such as databases.
- Schedule reboots at quiet times, and stagger them across servers in a cluster.
- Monitor services after update windows, and read the update reports.
- Third-party repositories (for example for PHP or Docker) are not updated by unattended-upgrades unless you add their origins.
Frequently asked questions
Are automatic updates safe on a production server?
Automatic security updates are generally safe and strongly recommended. Automatically applying all updates is better suited to non-critical systems or servers with good backups and monitoring.
How do I check if unattended-upgrades is running?
Run systemctl status unattended-upgrades, check the timers with systemctl list-timers apt-daily*, and read /var/log/unattended-upgrades/.
Do automatic updates reboot the server?
Only if you enable it (Automatic-Reboot on Ubuntu/Debian, reboot = when-needed with dnf-automatic).
How do I turn off automatic updates?
On Ubuntu/Debian, run sudo dpkg-reconfigure unattended-upgrades and choose No. On RHEL-family systems, run sudo systemctl disable --now dnf-automatic.timer.


