How to Use Screen on Your Linux VPS
With Screen you can run terminal sessions in the background. This way processes like a Minecraft server keep running even when you close the SSH connection.
Install Screen
Update system
First, update the package lists:bashsudo apt updatesudo apt updateInstall Screen
Install Screen with the following command:bashsudo apt install screen -ysudo apt install screen -y
Use Screen
Start a new session
Start a new Screen session with a name:
screen -S my-sessionscreen -S my-sessionYou are now inside the Screen session and can run commands.
Detach session
To keep the session running in the background, press:
Ctrl + A, then DCtrl + A, then DThe session will continue running in the background, even if you close the SSH connection.
List sessions
Show all running Screen sessions:
screen -lsscreen -lsReattach session
Reconnect to a running session:
screen -r my-sessionscreen -r my-sessionEnd session
To completely end a session, type inside the session:
exitexitExample: Minecraft Server
Start Screen session
Create a new session for the Minecraft server:bashscreen -S minecraftscreen -S minecraftStart server
Navigate to the server directory and start the server:bashcd /home/minecraft/server java -Xmx4G -Xms4G -jar server.jar noguicd /home/minecraft/server java -Xmx4G -Xms4G -jar server.jar noguiDetach session
PressCtrl + A, thenD. The Minecraft server will continue running in the background.Reconnect later
To open the server console again:bashscreen -r minecraftscreen -r minecraft
All commands
| Command | Description |
|---|---|
screen -S name | Start a new session with name |
screen -ls | List all sessions |
screen -r name | Reattach to a session |
Ctrl + A, D | Detach session |
exit | End session |