Automate Security Updates and Reboots on Ubuntu 26.04 LTS
On Ubuntu 26.04 LTS, you can set up daily automatic updates with unattended-upgrades and automatic reboots when needed. To include regular updates, add -updates. Ubuntu Server documentation
Run the following on your target Ubuntu server.
1. Install Required Packages
sudo apt-get update
sudo apt-get install -y unattended-upgrades update-notifier-common
2. Configure Automatic Updates and Reboots
The following example checks for updates daily and reboots at 4:00 AM if needed.
sudo tee /etc/apt/apt.conf.d/99-local-auto-upgrades >/dev/null <<'EOF'
APT::Periodic::Enable "1";
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "1";
Unattended-Upgrade::Allowed-Origins {
"${distro_id}:${distro_codename}";
"${distro_id}:${distro_codename}-security";
"${distro_id}:${distro_codename}-updates";
};
Unattended-Upgrade::Automatic-Reboot "true";
Unattended-Upgrade::Automatic-Reboot-WithUsers "true";
Unattended-Upgrade::Automatic-Reboot-Time "04:00";
EOF
sudo systemctl enable --now apt-daily.timer apt-daily-upgrade.timer
04:00 is based on the server’s timezone. To set it to Japan Time, run the following. This configuration will also disconnect your SSH connection. Ubuntu Server documentation
sudo timedatectl set-timezone Asia/Tokyo
3. Verify the Configuration
You can test the setup without performing actual updates or reboots.
sudo unattended-upgrade --dry-run --debug
systemctl list-timers 'apt-daily*'
Check the update history with:
sudo tail -n 100 /var/log/unattended-upgrades/unattended-upgrades.log
Note that 4:00 AM is the reboot time, while updates are executed according to the standard timer schedule. Services may restart during updates. Additionally, this configuration targets only Ubuntu’s official updates, not fully matching apt-get upgrade with any added external repositories.
Comments
No comments yet.