Overview
screen and tmux are terminal multiplexers that allow you to run a game server in a session that persists even after you disconnect from SSH. This is useful for manual server management, testing, or running alongside systemd services.
Prerequisites
- Linux VPS with SSH access
- Game server files ready to run (e.g., Minecraft server jar)
- Basic command-line knowledge
Part 1: Using screen (simpler, widely available)
Step 1: Install screen (if not already installed)
sudo apt update && sudo apt install screen -y
Step 2: Start a new screen session
screen -S minecraft-server
This creates a new session named "minecraft-server". You'll see a blank terminal.
Step 3: Navigate to your server directory and start the server
cd /home/minecraft/server
java -Xmx2048M -Xms2048M -jar server.jar nogui
The server will start normally. Leave it running.
Step 4: Detach from the session (keep it running in the background)
Press Ctrl+A then D (hold Ctrl+A, release, then press D).
The server continues running. You'll see a message like "Detached from 2345.minecraft-server".
Step 5: Reattach to the session later
screen -r minecraft-server
Or list all sessions and pick one:
screen -ls
Output example:
CODE5
Step 6: Stop the server gracefully
Reattach to the session (screen -r minecraft-server), then in the server console type:
stop
The server will shut down. Press Ctrl+A then D to detach, or just close the window.
Step 7: Kill a session (if needed)
screen -X -S minecraft-server quit
Part 2: Using tmux (more powerful)
Step 1: Install tmux
sudo apt update && sudo apt install tmux -y
Step 2: Start a new tmux session
tmux new-session -s minecraft-server
This creates a new session named "minecraft-server".
Step 3: Navigate and start your server
cd /home/minecraft/server
java -Xmx2048M -Xms2048M -jar server.jar nogui
Step 4: Detach from the session
Press Ctrl+B then D (hold Ctrl+B, release, then press D).
The server keeps running in the background.
Step 5: Reattach to the session
tmux attach -t minecraft-server
List all sessions:
tmux list-sessions
Step 6: Stop the server gracefully
Reattach to the session, type stop in the server console, and let it shut down.
Step 7: Kill a session
tmux kill-session -t minecraft-server
Key Commands 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, D | Ctrl+B, D |
| Kill session | screen -X -S name quit | tmux kill-session -t name |
Tips
- Multiple windows in one session (tmux): Press Ctrl+B, then C to create a new window. Use Ctrl+B, N / P to switch between windows.
- Scroll back through output: In screen, press Ctrl+A, [ to enter copy mode; press Space to select, then Enter to copy. In tmux, press Ctrl+B, [ (same navigation).
- Log server output: Start the server with output redirection:
```bash
java -Xmx2048M -Xms2048M -jar server.jar nogui > server.log 2>&1
```
Then tail -f server.log in another terminal to watch in real-time.
- Auto-start on reboot: For persistence across reboots, use systemd services instead.
Troubleshooting
Session is attached but I can't detach:
- Try force-detaching: screen -d minecraft-server or tmux detach-client -t minecraft-server
Server output is frozen:
- The session may have crashed. Reattach and check for error messages.
Accidentally killed the session:
- If you killed the terminal window without properly detaching, the process might still be running. Check with ps aux | grep java and kill it manually if needed.
Next Steps
- Run a Minecraft server as a systemd service for automatic restarts and boot-time startup
- Add plugins or mods to enhance your server