How to Set Up Automatic Updates on Linux
With unattended-upgrades your Ubuntu or Debian server installs security updates automatically. That keeps your VPS protected against known vulnerabilities, even if you do not log in every day yourself. In this article you set up automatic updates, choose whether the server may reboot by itself and check that everything works. If you use AlmaLinux, read at the bottom how this works with dnf-automatic.
Step 1: install unattended-upgrades
apt update
apt install unattended-upgrades -y Step 2: enable automatic updates
Choose Yes in the window that appears:
dpkg-reconfigure -plow unattended-upgrades This creates the 20auto-upgrades file with these settings:
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "1"; Step 3: decide whether the server may reboot by itself
Some updates, such as a new kernel, only take effect after a reboot. In the configuration file you set whether and when the server reboots automatically:
Unattended-Upgrade::Automatic-Reboot "true";
Unattended-Upgrade::Automatic-Reboot-Time "04:00"; Choose a time when your server is used least. If you want to decide yourself when the server reboots, leave this set to false.
Step 4: test the settings
A test run shows which updates would be installed, without changing anything:
unattended-upgrade --dry-run --debug You find the log files of automatic updates in /var/log/unattended-upgrades/.
Automatic updates on AlmaLinux
On AlmaLinux you use dnf-automatic. Install the package and set apply_updates to yes in the configuration file:
dnf install dnf-automatic -y
nano /etc/dnf/automatic.conf
systemctl enable --now dnf-automatic.timer Tips
- Take snapshots: take a snapshot before major manual upgrades, so you can roll back.
- Check regularly: occasionally check the log files to see whether updates were installed correctly.
Related articles
Rent a Linux VPS with root access
Ubuntu, Debian or AlmaLinux with full root access via SSH, enterprise Ceph storage with high availability and hosting in Amsterdam.