How to Upgrade Ubuntu Server Over SSH

You can upgrade Ubuntu over SSH, but there’s a risk: if your SSH connection drops during the upgrade, the process might stop and cause problems.

So what you should do is use a screen session over SSH to prevent losing the upgrade session.

Why Use Screen?

When you run commands inside a screen session, they keep running in the background, even if your SSH connection drops or you close the terminal. This makes upgrading over SSH safer and more reliable.

Steps to Upgrade Ubuntu Server Over SSH Using Screen

Install screen if it’s not already installed:

sudo apt update
sudo apt install screen

Start a new screen session using the screen command:

screen

Next, run the upgrade process inside the screen session. For example, here’s how you upgrade Ubuntu 22 to 24.

Recovering a Screen Session

When you start the upgrade inside a screen session, it will keep running even if your SSH connection is disconnected.

To get back into the screen session, log in to the server and run the screen -ls command. This will show a list of active screen sessions.

screen -ls

Then use the screen -r command to reconnect to the session.

screen -r ID
Upgrade Ubuntu Server Over SSH

Detach from Screen (Leave it Running)

To detach from a screen session while keeping it running in the background, press Ctrl + A, then press D.

Ctrl + A, then D

Notes

  • During the upgrade, the system may open an additional SSH port (usually 1022) for safety. This is normal.
  • Using screen helps prevent the upgrade from stopping if your SSH connection drops.