Automate Monthly Updates on Ubuntu 24.04 for a VPN Server
Keep your Ubuntu-based VPN server secure, stable, and low maintenance by automating system updates on a monthly schedule. The setup below uses a small shell script, a root cron job, optional reboot logic, and a simple log file so you can confirm everything ran as expected.
What you will set up
- A lightweight update script that handles package refresh, upgrades, and cleanup
- A monthly schedule that runs at a quiet hour
- An optional automatic reboot after updates
- Clear verification steps with a timestamped log
Create a reliable update script
1) Create the script file as root:
sudo nano /usr/local/bin/auto-update.sh
2) Paste the following lines into the file:
#!/bin/bash
apt-get update && apt-get dist-upgrade -y
apt-get autoremove -y
apt-get autoclean
echo “Full system update completed on $(date)” >> /var/log/sys_update.log
3) Make it executable:
sudo chmod +x /usr/local/bin/auto-update.sh
This script updates package lists, performs a full upgrade, removes unneeded packages, cleans cached data, and appends a timestamp to a simple log at /var/log/sys_update.log.
Schedule monthly updates with cron
Open the root crontab:
sudo crontab -e
Add this line at the end to run updates at 03:00 on the first day of every month:
0 3 1 * * /usr/local/bin/auto-update.sh
Using the root crontab ensures the script has the required privileges. The time used is the server’s local system time.
Optional: reboot after updates
If your environment allows automatic reboots, you can reboot once updates complete. Edit the script:
sudo nano /usr/local/bin/auto-update.sh
Add this line at the very bottom:
/sbin/reboot
Only enable this if a reboot during that maintenance window is acceptable. Some kernel or core library updates are fully applied only after a restart.
Verify it is working
- List scheduled cron jobs for root: sudo crontab -l
- Check the update log: cat /var/log/sys_update.log
- Optionally, run the script once by hand to test: sudo /usr/local/bin/auto-update.sh
If the log shows recent timestamps, your automated updates are operating correctly.
Practical tips
- Ensure the script uses absolute paths if your environment has a minimal PATH in cron. The commands above work on standard Ubuntu root cron defaults.
- Keep the script small and focused. It is easy to maintain and audit.
- If the log grows large, consider rotating it with your existing log rotation method.
Wrap-up
With this small setup, your Ubuntu 24.04 VPN server stays consistently updated without manual effort. It is simple, auditable, and safe to run on production nodes during a defined maintenance window. Keep your #Ubuntubased #VPN #Server #Updated.