DEV Community

Reginald F. Johnson
Reginald F. Johnson

Posted on

Keep your Ubuntu‑based VPN Server Updated

🔄 Automate Monthly System Updates on Ubuntu 24.04

A simple, reliable way to keep your Ubuntu‑based VPN server fully updated.

This guide shows you how to create an update script, schedule it to run monthly, optionally reboot afterward, and verify everything is working.


📝 Step 1: Create the Update Script

First, create the script file:

sudo nano /usr/local/bin/auto-update.sh
Enter fullscreen mode Exit fullscreen mode

Paste the following into the file:

#!/bin/bash
# Update package lists and upgrade everything
apt-get update && apt-get dist-upgrade -y

# Clean up old files
apt-get autoremove -y
apt-get autoclean

# Log completion time
echo "Full system update completed on $(date)" >> /var/log/sys_update.log
Enter fullscreen mode Exit fullscreen mode

Make the script executable:

sudo chmod +x /usr/local/bin/auto-update.sh
Enter fullscreen mode Exit fullscreen mode

⏱️ Step 2: Schedule Monthly Updates with Cron

Open the root crontab:

sudo crontab -e
Enter fullscreen mode Exit fullscreen mode

Add this line at the bottom:

0 3 1 * * /usr/local/bin/auto-update.sh
Enter fullscreen mode Exit fullscreen mode

This runs the update script at 3:00 AM on the 1st day of every month.


🔁 Step 3 (Optional): Enable Auto‑Reboot

If you want the server to reboot after updates:

Open the script again:

sudo nano /usr/local/bin/auto-update.sh
Enter fullscreen mode Exit fullscreen mode

Add this line at the very bottom:

/sbin/reboot
Enter fullscreen mode Exit fullscreen mode

Save and exit.


✅ Step 4: Verify Everything

Check your scheduled cron jobs:

sudo crontab -l
Enter fullscreen mode Exit fullscreen mode

Check the update log:

cat /var/log/sys_update.log
Enter fullscreen mode Exit fullscreen mode

If you see timestamps, your automated updates are working correctly.


🎉 Done!

Your Ubuntu 24.04 VPN server will now stay updated, clean, and low‑maintenance with almost no effort.

Top comments (0)