How to auto update and upgrade Ubuntu server once a day with unattended upgrades

Ubuntu 18.04 Manual

Do you feel it’s a hassle with all the new packages that needs updating?
Typing:

sudo apt-get dist-upgrade

Almost every week you log in to Ubuntu. Upgrades and updates should be automated. It’s done very easy once and for all. Just continue reading.

The unattended-upgrades package is the best practice for automating the updating of Ubuntu. For headless machines like the WordPress JeOS VPS server, this is a major security gain and a great timesaver.

You can set up unattended-upgrades by typing this in a terminal:

sudo apt-get install unattended-upgrades

Then configure unattended upgrades using this command:

sudo dpkg-reconfigure unattended-upgrades

That’s all. Ubuntu will now update itself every day.

If unattended upgrades fail, then configure manually

If not working as needed. Open the configuration files and customize to fit your needs.

Documentation on how to customize the update and upgrade are available in the Ubuntu documentation.

You can not use this tool to upgrade from Ubuntu 14 to Ubuntu 16. It will only upgrade and update packages.

First, edit the config file:

sudo nano /etc/apt/apt.conf.d/50unattended-upgrades

Change the values to look like this:

// Automatically upgrade packages from these (origin:archive) pairs
Unattended-Upgrade::Allowed-Origins {
        "${distro_id}:${distro_codename}-security";
        "${distro_id}:${distro_codename}-updates";
        "${distro_id}:${distro_codename}-proposed";
        "${distro_id}:${distro_codename}-backports";
};

// List of packages to not update (regexp are supported)
// Unattended-Upgrade::Package-Blacklist {
//      "libc6-i686";
// };

The second file to edit is this one:

sudo nano /etc/apt/apt.conf.d/10periodic

Change it to look like this:

::Periodic::Update-Package-Lists "1";
APT::Periodic::Download-Upgradeable-Packages "1";
APT::Periodic::AutocleanInterval "7";
APT::Periodic::Unattended-Upgrade "1";

Automatic unattended updates for Ubuntu 20.04 LTS

Test if it already installed:

sudo unattended-upgrades --dry-run

Run the upgrade:

sudo apt update && sudo apt upgrade

sudo nano /etc/apt/apt.conf.d/50unattended-upgrades

Sending e-mail:

sudo apt install bsd-mailx

sudo apt install apt-listchanges

sudo nano /etc/apt/listchanges.conf

Change to:

email_address=t@tbt.biz

Postfix log

sudo nano /var/log/mail.log

Remove log

sudo rm /var/log/mail.log

Restart Postfix

sudo systemctl restart postfix

Flush e-mail queue

sudo postqueue -f

Sources

Set up automatic unattended updates for Ubuntu 20.04

Set Up Automatic Security Update (Unattended Upgrades) on Ubuntu

Set up automatic unattended updates for packages from ondrej

Using Unattended-Upgrades on Debian and Ubuntu

"LP-PPA-ondrej-php:${distro_codename}";