The Linux server security is indeed an essential task for sysadmins. One of the most fundamental ways to keep the Ubuntu server secure is by installing security updates on time to patch vulnerabilities. By default, the unattended-upgrades package installed, but you still need to configure a few options. It will automatically install software updates, including security updates. This page shows how to configure security updates automatically when released by the Ubuntu security team using an unattended-upgrades package.
Automatic unattended updates for Ubuntu 20.04 LTS
- Update the Ubuntu 20.04 LTS server for security patches, run:
[admin@aws-ec2-007]$ sudo apt update && sudo apt upgrade
- Install unattended upgrades on Ubuntu if not installed. Type the following apt command
[admin@aws-ec2-007]$ sudo apt install unattended-upgrades apt-listchanges bsd-mailx
- Turn on unattended security updates, run:
[admin@aws-ec2-007]$ sudo dpkg-reconfigure -plow unattended-upgrades
- Configure automatic unattended updates, enter:
[admin@aws-ec2-007]$ sudo vi /etc/apt/apt.conf.d/50unattended-upgrades
Set up alert email ID:
Unattended-Upgrade::Mail "vivek@server1.cyberciti.biz";
Automatically reboot Ubuntu box WITHOUT CONFIRMATION for kernel updates:
Unattended-Upgrade::Automatic-Reboot "true";
Finally edit the /etc/apt/listchanges.conf and set email ID:
email_address=vivek@server1.cyberciti.biz
Save and close the file.It would be best if you have a working email server to get an alert. You can always use AWS SES with Postfix MTA to route email safely.
- Verify that it is working by running the following command:
[admin@aws-ec2-007]$ sudo unattended-upgrades --dry-run
Ubuntu automatic unattended updates sample email alert
Configuring Unattended-Upgrade::Mail in 50unattended-upgrades file enables unattended-upgrades to email a sysadmin detailing any packages that need upgrading or have problems. The Ubuntu server sent an update report via email as follows:
Displaying automatic updates logs from the CLI
Now that you set up automatic updates on Ubuntu Server 20.04 LTS. It is time to see logs. Hence, we can use command such as grep command or cat command or more command/egrep command as follows:
[admin@aws-ec2-007]$ sudo cat /var/log/unattended-upgrades/unattended-upgrades.log
[admin@aws-ec2-007]$ sudo tail -f /var/log/unattended-upgrades/unattended-upgrades.log
[admin@aws-ec2-007]$ sudo grep 'linux-image' /var/log/unattended-upgrades/unattended-upgrades.log
And you are done. I hope this helps you to keep the server or virtual machine running in cloud current with the latest security updates automatically.
Conclusion
You learned how to configure automatic unattended updates for your Ubuntu Linux based server up-to-date. It is a simple and easiest way to protect your server from vulnerabilities. This method is also beneficial when you administrate multiple servers. Manually updating the system and applying patches can be a very time-consuming process. However, for a large number of servers/VMs, I would recommend something like Ansible:
- Ansible apt update all packages on Ubuntu / Debian Linux
- Ansible reboot a Debian/Ubuntu Linux for kernel update and wait for it
🐧 Get the latest tutorials on Linux, Open Source & DevOps via:
- RSS feed or Weekly email newsletter
- Share on Twitter • Facebook • 6 comments... add one ↓
Category | List of Unix and Linux commands |
---|---|
File Management | cat |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Network Utilities | dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time |
Searching | grep • whereis • which |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |
When i run
unattended-upgrades --dry-run
It said pending. why?
Remote the --dry-run option which just simulate installing updates, do not actually apply updates.
Hello, I ran the command with and without debug mode and it didn’t send me a notification mail (gmail). The configuration files are exactly the same as the publication
Please could you help me?
You need working email server to send email.
I did all as your tutorial but when I run command: sudo unattended-upgrades –dry-run
There is nothing result, what does that mean?
It means currently no updates available.