Set up unattended-upgrades on Ubuntu 20.04

Package upgrades can be set up to install updates on Ubuntu without user intervention.

Install unattended-upgrades

apt install unattended-upgrades

Install mailx & Postfix

apt install bsd-mailx

If this does not install Postfix, install it now.

apt install postfix

This will install also install Postfix. mailx is what unattended upgrades uses to send external mail.

Configure unattended-upgrades

Edit /etc/apt/apt.conf.d/50unattended-upgrades. This file is mostly self explanatory. The options can be enabled by deleting un-commenting the line. At the very least, configure the following:

  • Unattended-Upgrade::Mail “your@email.com”; to allow sending notifications to your e-mail address.
  • Unattended-Upgrade::Automatic-Reboot “true”; to enable auto-reboots
  • Unattended-Upgrade::Remove-Unused-Kernel-Packages “true”; to remove kernel-related packages. This is usually done using apt autoremove.
  • Unattended-Upgrade::Remove-New-Unused-Dependencies “true”; - remove unneeded dependancies. Also manually done with apt autoremove.
  • Unattended-Upgrade::Remove-Unused-Dependencies “false”; - remove unused packages, also, apt autoremove.

Restart unattended-upgrades

systemctl restart unattended-upgrades

Configure Postfix

Edit /etc/postfix/main.cf. Configuration of postfix is outside the scope of this article. For my purposes, I use a relay, so I edit and uncomment relayhost = to point to my relay.

Test mail

mailx -vvv -s "Subject" your@e-mail.com

Press CTRL D to send the email.

Test your set up

unattended-upgrades --dry-run -–debug