Lesson 2: Updating your VPS
3 mins read
This article describes why you need to continually update your VPS and the impact it has on your security.
Why do you Update your VPS Constantly?
Keeping your VPS services and packages up to date helps prevent vulnerabilities that can be exploited by hackers when using older versions of these code bases. You should always install the latest version available of software as exploits are discovered in older versions regularly and developers have to update their codes to remove these back doors that can be exploited to damage your systems.
Updating your server is Linux is very simple and can be configured to run automatically on a daily, weekly, or monthly basis.
Should you Back-up your VPS Before Updating?
Normally nothing goes wrong when updating and 9 times out of 10 you will usually be ok.
However, making changes to your server can always run the risk of having unexpected results when updating and upgrading to new versions and packages. Code can sometimes break or installations can get hung up. It is recommended to back up your system before every update just in case you experience adverse effects after an update.
To backup your server see here:
How do you Update your VPS?
To check if you have any updates available, you will see a message in your terminal when you SSH login to your VPS similar to this one:
To update will depend on your Linux distribution, but for our case since we are using Ubuntu we will run the following commands:
sudo apt -y update
Once complete, run the next command:
sudo apt -y upgrade
Your system will install and upgrade all the necessary packages.
How Often Should you Update your VPS?
It’s recommended to run updates at least once a week.
How to Create Automated Updates for VPS?
To create a script and cron job that auto-updates and upgrades your Ubuntu VPS once a week, follow these steps:
- Create a new script file using your preferred text editor:
sudo nano /root/update-vps.sh
- Add the following commands to the script file:
#!/bin/bash # Update package lists apt update # Upgrade installed packages apt upgrade -y # Clean up package cache and old dependencies apt autoremove -y apt autoclean -y
This script will update the package lists, upgrade any installed packages, and then clean up the package cache and old dependencies.
- Make the script executable:
sudo chmod +x /root/update-vps.sh
- Add a cron job to run the script once a week:
sudo crontab -e
This will open the cron tab configuration file in your default text editor.
- Add the following line to the file to run the script every Sunday at 3 am:
0 3 * * 0 /root/update-vps.sh
This cron job will run the script at 3 am every Sunday. You can customize the timing as per your requirement.
- Save and close the file.
That’s it! Your Ubuntu VPS will now automatically update and upgrade itself once a week using the script and cron job you created.
- 2023/03/30 Lesson 1: SSH the Secure Shell Protocol
- 2023/03/30 What is Linux Security?
- 2023/03/29 How to Open Terminal on Linux?
- 2023/03/29 How to Open Terminal on Mac?
- 2023/03/29 How to Open Terminal on Windows?
Authored By Is-Rael Landes
Is-Rael Landes, a good man living on the earth, loving making website, teaching others and coding.