Guides ยท Oct 15, 2026
Keep a Game Server Running on a VPS: systemd vs tmux vs screen
How to run Minecraft, Valheim or any Linux game server in the background on a VPS: tmux and screen for quick sessions, or a systemd service for auto-restart.
A game server started in an SSH window stops the moment you disconnect. To keep it running on a game server VPS you can use a terminal multiplexer such as tmux or screen, or turn it into a systemd service that starts at boot and restarts itself. This guide shows both so you can pick what fits.
Option 1: tmux (quick and interactive)
tmux keeps a terminal session alive on the server so you can detach and come back later, and you can type commands into the server console.
sudo apt install tmux
tmux new -s game
# start your server inside, for example:
java -Xms2G -Xmx4G -jar server.jar nogui
Detach with Ctrl+B then D. The server keeps running. Reattach later:
tmux attach -t game
screen works the same way (screen -S game, detach with Ctrl+A then D, reattach with screen -r game). The downside of both: nothing restarts the server after a crash or reboot.
Option 2: a systemd service (auto-restart)
For a server that should always be up, create a service. Replace the user, folder and start command with yours. This example is a Java server in /home/alex/mc:
sudo nano /etc/systemd/system/gameserver.service
[Unit]
Description=Game server
After=network-online.target
Wants=network-online.target
[Service]
User=alex
WorkingDirectory=/home/alex/mc
ExecStart=/usr/bin/java -Xms2G -Xmx4G -jar server.jar nogui
Restart=on-failure
RestartSec=10
[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable --now gameserver
journalctl -u gameserver -f
Use Restart=on-failure so that stopping the server on purpose does not immediately start it again.
Sending commands to a systemd server
A service has no interactive console by default. Common options are the server's own RCON feature (Minecraft supports it, set a strong password and keep the port closed to the internet), a panel such as Pterodactyl, or running the server inside tmux started by the service. If you want to type commands often, tmux may be the better fit for you.
Open the right ports
Your game needs its port reachable. Check the game's documentation for the port number and whether it uses TCP, UDP or both (Minecraft Java uses TCP 25565 by default). Then allow it in the firewall:
sudo ufw allow 25565/tcp
See the UFW firewall guide for details. Do not expose RCON or admin ports publicly.
Memory: do not give the game everything
Leave room for the operating system. If your server has 8 GB of RAM, a 6 GB heap for the game is usually plenty. Our game server sizing guide explains how to pick a plan, and a small swap file adds a safety margin.
Back up the world
Crashes and bad updates happen. Copy your world or save folder regularly, and stop or flush the server first if the game requires it to avoid corrupt backups. restic makes encrypted, incremental backups easy.
Which should I choose?
Use tmux or screen while you are setting up and testing. Move to a systemd service once the server is stable and you want it to survive crashes and reboots. For a complete Minecraft example, follow how to run a Minecraft server on Ubuntu.
Frequently asked questions
How do I keep a game server running after I close SSH?
Start it inside tmux or screen and detach, or run it as a systemd service. Both keep it running after you disconnect.
tmux or systemd for a game server?
tmux gives you an interactive console but no automatic restart. systemd restarts the server after crashes and reboots but has no console by default.
Which port should I open for my game server?
It depends on the game. Check its documentation for the port and protocol, then allow only that in your firewall.
How much RAM should I give the game server?
Leave at least 1 to 2 GB for the operating system. For example, on an 8 GB server a 5 to 6 GB heap is a common choice.
Related guides
- How to Set Up a Minecraft Server on an Ubuntu VPS
- How to Choose a VPS Size for a Game Server (RAM, CPU, Disk)
- UFW Firewall on an Ubuntu VPS: Rules, Rate Limiting and Docker Caveats
Need a server for this?
Every TidalVPS VPS comes with full root access, unmetered traffic, daily backups and DDoS protection.