A game process started in a normal SSH session dies when that session ends. screen and tmux keep a terminal session on the VPS so you can detach, close SSH, and come back later. Use this for a first test. For something that starts on boot and restarts after a crash, use a systemd unit instead:
- Run a Minecraft server as a systemd service (auto-start)
- Keep a Game Server Running and Auto-Restarting with systemd
Need a VPS first? See VPS. Credentials, the IPv4, and an out-of-band console sit on that server in the portal.
Before you start
- Sign in at the portal, open the VPS service, and keep that page open.
- Connect with a sudo user, or
rooton a fresh box.
- Connect to your VPS via SSH from macOS or Linux
- Connect to your VPS via SSH from Windows
- Have the game files already installed. Examples:
- Set up a Minecraft Java Edition server on Linux
- Set up a Valheim dedicated server
- Set up a Rust dedicated server
- Set up a Counter-Strike 2 dedicated server with SteamCMD
If SSH from your computer will not connect, open the console on the same VPS service. That session does not need port 22 from your network.
We document Ubuntu 24.04 LTS. Debian is close. For AlmaLinux or Rocky Linux, install with sudo dnf install -y screen or sudo dnf install -y tmux, or open a support ticket and we will match the packages.
Run the game as the dedicated user you created (minecraft or steam), not as root.
Use screen (simple, widely available)
Install screen
sudo apt update
sudo apt install -y screen
Start a named session
As the game user:
screen -S minecraft
That opens a fresh shell inside a session named minecraft. Use another name (valheim, rust, cs2) if that is the game you are running.
Start the game
Minecraft example (match the -Xmx you chose in the Minecraft article):
cd /home/minecraft/server
java -Xmx2G -Xms2G -jar server.jar nogui
SteamCMD games use the start script from that game's article, for example ~/valheim_start.sh. Leave the process in the foreground. Do not add &.
Detach (leave it running)
Press Ctrl+A, release, then press D.
The game keeps running. You should see a line like Detached from ...minecraft. You can close SSH.
Reattach later
screen -r minecraft
List sessions if you forgot the name:
screen -ls
Example:
There is a screen on:
2345.minecraft (Detached)
2346.valheim (Detached)
If screen -r says the session is already attached (for example you left it open in another window), force the old client off and attach here:
screen -d -r minecraft
Stop the game cleanly
Reattach, then type the game's own stop command in that console (stop on Minecraft). Wait for it to exit. Then type exit to close the screen session, or start the game again.
Do not kill the session while the world is still writing to disk.
End a session
If the process is already stopped and you only want to drop the session:
screen -X -S minecraft quit
Use tmux (more features)
Install tmux
sudo apt update
sudo apt install -y tmux
Start a named session
tmux new-session -s minecraft
Start the game
Same commands as in the screen section. Stay in the foreground.
Detach
Press Ctrl+B, release, then press D.
Reattach later
tmux attach -t minecraft
List sessions:
tmux list-sessions
If a stale client is still attached:
tmux attach -d -t minecraft
Stop the game cleanly
Reattach, type stop (or that game's quit command), wait for the process to exit.
End a session
tmux kill-session -t minecraft
Only do this after the game has shut down.
Command comparison
| Action | screen | tmux |
|---|---|---|
| Create session | screen -S name | tmux new-session -s name |
| List sessions | screen -ls | tmux list-sessions |
| Attach | screen -r name | tmux attach -t name |
| Detach | Ctrl+A, then D | Ctrl+B, then D |
| Take over an attached session | screen -d -r name | tmux attach -d -t name |
| End session | screen -X -S name quit | tmux kill-session -t name |
Extra tips
- Another window in the same tmux session. Ctrl+B, then C. Switch with Ctrl+B, then N or P.
- Scroll back. In screen: Ctrl+A, then
[. In tmux: Ctrl+B, then[. Arrow keys move. Press Q to leave copy mode. - A log file as well. You can still write a log next to the console:
```bash
java -Xmx2G -Xms2G -jar server.jar nogui | tee -a server.log
```
tee keeps the console you type into and appends a copy to server.log.
- After a reboot, screen and tmux are empty. They do not start the game again. Use Keep a Game Server Running and Auto-Restarting with systemd, or the Minecraft systemd unit.
- Players still cannot join. Open the ports first: Open the Right Firewall Ports for Your Game Server.
If something is stuck
screen -r says there is no session. The process is gone. Start a new session and launch the game again. A reboot also clears every session.
You cannot detach. From a second SSH login, try screen -d minecraft or tmux detach-client -t minecraft, then attach again.
The console looks frozen. Press Enter. If nothing changes, you may have entered copy/scroll mode (Ctrl+A [ or Ctrl+B [). Press Q or Escape.
You closed the SSH window without detaching. The session is usually still there. Run screen -ls or tmux list-sessions and attach.
A stray process is still using the port. After you thought you stopped the game:
ps aux | grep -E 'java|valheim|RustDedicated|cs2' | grep -v grep
Stop it from the game console if you can still attach. If you must, open a support ticket before you kill -9 a world that is still saving.
Still stuck? Open a support ticket. Tell us the VPS service, whether you used screen or tmux, and the session name. Do not send the password.
What to do next
- Auto-start on reboot: Run a Minecraft server as a systemd service (auto-start) or Keep a Game Server Running and Auto-Restarting with systemd
- Plugins or mods: Add plugins (Paper/Spigot) or mods to a Minecraft server
- Open the game ports: Open the Right Firewall Ports for Your Game Server
A step is unclear? Open a support ticket and we will walk through the VPS with you.