Auto-updating Ubuntu 20.04 in less than 2 minutes

Auto-updating Ubuntu 20.04 in less than 2 minutes

If you are like me and deploy lots of small instances of VMs all over the place for various functions, you will find applying updates to them all consistently and in a responsive manner a logistical issue. Fortunately, there is an auto-update function within Ubuntu which can be configured in a few minutes.

This very quick snippet of code is intended to be your all-in-one script for applying system security updates when they come out, and queue up your system for a reboot when required. A word of warning however – if you have not configured services to start on boot, this may break your capability until you manually intervene.

sudo apt install -y unattended-upgrades update-notifier-common
sudo cp /etc/apt/apt.conf.d/50unattended-upgrades ~/50unattended-upgrades.backup
echo 'Unattended-Upgrade::Automatic-Reboot "true";' >> /etc/apt/apt.conf.d/50unattended-upgrades
echo 'Unattended-Upgrade::Automatic-Reboot-WithUsers "true";' >> /etc/apt/apt.conf.d/50unattended-upgrades
sudo dpkg-reconfigure -plow unattended-upgrades

The default configuration of 50unattended-upgrades should be fit for purpose as it. There are however two lines which need to be added to enable the automatic reboot, and also automatic reboot with users connected (could be optional, it depends on your system use case etc).

Contents of 50unattended-upgrades

When prompted by dpkg-configure, select ‘Yes’ to automatically download and install stable updates.

dpkg-reconfigure -plow unattended-upgrades prompt

Leave a Reply

7 − two =