I have minimal Ubuntu linux 18.04 LTS server setup in the cloud. I read that one can configure Ubuntu Linux to download and install security updates when released automatically. How can I set up automatic security updates on Ubuntu Linux 18.04 or 16.04 LTS system?
Introduction : It is true that the Linux server security is an essential task for sysadmins. One of the most fundamental ways to keep server or desktop secure is by installing security updates to patch vulnerabilities on time. One can use theapt-get command or apt commandto install security updates. This page shows you how to configure Ubuntu Linux system to install security updates automatically when released by Ubuntu security team.
Ubuntu Enable & Setup Automatic Unattended Security UpdatesYou may be wondering why do I need an unattended way and installs security updates? Applying updates on a frequent basis is an important part of keeping systems secure. By default, updates need to be applied manually using package management tools. However, you can choose to have Ubuntu automatically download and install important security updates.
Step 1. Install unattended-upgrades packageWarning: Some security risks associated with running unattended software upgrades without supervision do exists, but there are also benefits. Use your judgment when in doubt.
Type the followingapt-get command orapt command to install unattended-upgrades package:
$ sudo apt install unattended-upgrades apt-listchanges bsd-mailx
Step 2. Ubuntu enable unattended security updates
Run the following command:
$ sudo dpkg-reconfigure -plow unattended-upgrades
You should see /etc/apt/apt.conf.d/20auto-upgrades file created due to above command. One can view the same withcat command:
$ cat /etc/apt/apt.conf.d/20auto-upgradesSample outputs (make sure it is as follows; if NOT update it manually):
APT::Periodic::Update-Package-Lists "1"; APT::Periodic::Unattended-Upgrade "1"; APT::Periodic::AutocleanInterval "7"; APT::Periodic::Unattended-Upgrade "1";
Step 3. Configuration fileYou need to edit the file named /etc/apt/apt.conf.d/50unattended-upgrades using a text editor such as vim command or nano command:
$ sudo vi /etc/apt/apt.conf.d/50unattended-upgradesMake sure config is as follows:
Unattended-Upgrade::Allowed-Origins { "${distro_id}:${distro_codename}"; "${distro_id}:${distro_codename}-security"; // Extended Security Maintenance; doesn't necessarily exist for // every release and this system may not have it installed, but if // available, the policy for updates is such that unattended-upgrades // should also install from here by default. "${distro_id}ESM:${distro_codename}"; // "${distro_id}:${distro_codename}-updates"; // "${distro_id}:${distro_codename}-proposed"; // "${distro_id}:${distro_codename}-backports"; };
One can skip packages to not update (optional):
// List of packages to not update (regexp are supported) Unattended-Upgrade::Package-Blacklist { "linux-image"; "vim"; "nginx"; };
You need to configure an email address to get email when there is a problem or package upgrades. Of course you must have working email setup to this work:
//Send email to this address for problems or packages upgrades // If empty or unset then no email is sent, make sure that you // have a working mail setup on your system. A package that provides // 'mailx' must be installed. E.g. "user@example.com" Unattended-Upgrade::Mail "notify@server1.cyberciti.biz";
Save and close the file. Finally edit the file named /etc/apt/listchanges.conf using a text editor such as vim command/nano command:
$ sudo vi /etc/apt/listchanges.confSet email address from:
email_address=rootTo:
email_address=notify@server1.cyberciti.bizSave and close the file.
ConclusionYou learned how to install and configure the unattended-upgrades package to automatically install updated packages, and can be configured to update all packages or install security updates. For more info see this page .
This entry is 3 of 3 in the Applying Debian/Ubuntu Linux Security Updates/Patches series. Keep reading the rest of the series: How to apply Debian security patches How to keep Debian Linux patched with latest security updates automatically Ubuntu Enable & Setup Automatic Unattended Security Updates
Posted by: Vivek GiteThe author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics viaRSS/XML feed or weekly email newsletter .