VPS security · Practical guide

Keep your Ubuntu VPS updated and recoverable

Review package updates, plan restarts and check your application after maintenance.

Archive placement: September 2024

Coloured source code on a computer display

Keeping a VPS updated should be a repeatable maintenance task, not a command pasted into an SSH session and forgotten. Check capacity and backups, read the proposed changes, then verify the running application after any restart. This routine is for Ubuntu package updates; a full operating-system release upgrade is a separate job.

1. Check recovery before starting

Confirm the console works and you have a recent backup of important files and databases. A VPS recovery point and an application backup serve different purposes; a busy database may need a consistent export. Check the backup date instead of assuming the schedule ran.

Pick a maintenance time that suits your customers. Investigate low disk space or storage errors first, because updates need room to download and unpack files. Keep a way to contact support outside the VPS if the server becomes unavailable.

2. Check disk space and whether the package manager is busy

On the VPS: check storage and current package activity
df -h /
df -i /
ps -ef | grep -E "[a]pt|[d]pkg|[u]nattended-upgrade"

A nearly full filesystem or exhausted inodes can prevent an update even when downloads are small. Free space by identifying old backups or documented application logs, not by deleting package-manager files. If another update is active, let it finish. Do not remove apt or dpkg lock files just to silence a lock error; the files protect a real operation.

Check that your backup predates the maintenance and includes the databases you need. If the server is already unhealthy, capture the error and resolve the immediate capacity or storage problem before adding more changes.

3. Review the updates

These Ubuntu commands refresh package information and show available upgrades. The first updates the package list, not the installed software. Read repository errors before moving on.

On the Ubuntu VPS
sudo apt update
apt list --upgradable

Use supported repositories and check the release support period. A successful refresh does not make an end-of-life release supported again. Plan a release upgrade or migration separately from a routine patch session.

4. Install and handle restarts

Run the upgrade when you are ready to review its confirmation prompt. Pay attention to questions about configuration files you changed, and keep a copy so you can compare them with a new package version.

On the Ubuntu VPS: install reviewed updates
sudo apt upgrade

Restart or reboot when required, after checking recovery access. Updating a package on disk may leave an older process running until it restarts. A kernel update normally needs a reboot before the new kernel is used.

5. Decide whether to restart services or the whole VPS

On Ubuntu: check for a requested reboot and confirm the running kernel
ls /var/run/reboot-required
uname -r

If the marker file is absent, ls will report that it does not exist; that is not itself a maintenance failure. If it is present, plan a reboot. Some library updates also need application or web-service restarts. Read the package messages rather than assuming an installed update is already used by every running process.

Before rebooting, make sure the application has a clean stopping point, alert anyone affected, and confirm console access. After sudo reboot, open a new SSH connection and re-run uname -r. Do not repeatedly reboot a machine that does not come back; inspect its console for boot, disk or filesystem errors.

6. Check the service your visitors use

Open a new SSH connection and check the application from outside the VPS. This command lists units systemd considers failed. It is a useful starting point, not a complete application health check.

On the VPS: check failed services
systemctl --failed

Keep a short note of what changed and what you tested. If something fails, work from package messages and service logs rather than repeating the upgrade. Use your recovery plan if necessary, and resolve the cause before the next maintenance session.

7. Handle an interrupted update and prevent the next surprise

If an upgrade was interrupted, first confirm that no apt, dpkg or automatic-update process is still running. Read the error so you know whether the problem is storage, a repository or package configuration. These recovery commands are for an interrupted package state, not a routine speed-up trick.

On Ubuntu, only after the previous package process has stopped
sudo dpkg --configure -a
sudo apt --fix-broken install

Review any proposed installations or removals before confirming. If a configuration-file prompt appears, compare the file with your saved copy; replacing a customised web-server configuration can bring down the site. When package health is restored, check the service logs and public application again.

Consider Ubuntu’s unattended-upgrades for routine security fixes, but verify its configuration, logs and restart policy rather than assuming it is enabled or complete. Keep notifications and a regular maintenance check. Automatic patching does not replace testing, backups or a planned migration when the OS release reaches the end of support.

Common questions

Should I use apt full-upgrade every time?

Not automatically. It can remove packages to resolve dependencies. Start with apt upgrade, read what is held back, and review any broader change separately before approving it.

Can I downgrade a package if the application breaks?

Sometimes, but dependencies and database changes can make that unreliable. Diagnose the specific failure first; use a tested recovery point or rebuild plan when a simple configuration correction is not enough.

Further reading

← Back to all guidesDiscuss your hosting setup ↗