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:sudo apt update -
Install Screen
Install Screen with the following command:sudo apt install screen -y
Use Screen
Start a new session
Start a new Screen session with a name:
screen -S my-session
You are now inside the Screen session and can run commands.
Detach session
To keep the session running in the background, press:
Ctrl + A, then D
The session will continue running in the background, even if you close the SSH connection.
List sessions
Show all running Screen sessions:
screen -ls
Reattach session
Reconnect to a running session:
screen -r my-session
End session
To completely end a session, type inside the session:
exit
Example: Minecraft Server
-
Start Screen session
Create a new session for the Minecraft server:screen -S minecraft -
Start server
Navigate to the server directory and start the server:cd /home/minecraft/server java -Xmx4G -Xms4G -jar server.jar nogui -
Detach session
PressCtrl + A, thenD. The Minecraft server will continue running in the background. -
Reconnect later
To open the server console again:screen -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 |