tmux and screen for Game Servers: Keeping Steam Consoles Alive Past the SSH Window

TL;DR: A game server that only exists inside an SSH session dies with the session. Run SteamCMD and the game binary inside tmux or screen so the console survives disconnects, wrap it in a systemd unit for restart and boot behaviour, and keep the two roles separate: systemd owns the process, tmux owns the console. Mixing them is how you end up with two instances fighting over a lock file.

What actually happens when you close the terminal

SSH allocates a pseudo-terminal and delivers it to your shell. Every process started from that shell inherits the pty and a controlling terminal. When the session ends, the kernel sends SIGHUP to the foreground process group, and most game servers treat SIGHUP as “exit” — sometimes without saving. Even a server that ignores SIGHUP keeps its stdout attached to a pty that no longer exists and starts blocking when the buffer fills.

Three ways out, in increasing order of robustness:

  1. nohup binary &> log & — survives the disconnect, but you lose the console. Fine for a daemon, poor for a game server where the console is a management interface.
  2. tmux or screen — the console survives and is reattachable from anywhere.
  3. systemd — restart policy, resource limits, boot ordering and journal output, with tmux for interactive console access.

Use 2 and 3 together. The SteamCMD and systemd multi-instance guide covers the unit-file side for several servers on one machine; this article is about the console layer that sits beside it.

tmux or screen — pick one and standardise

Both solve the problem. The differences that matter on a game node:

  • tmux has cleaner scripting, vertical splits, a richer status bar and a better default for teams. Configuration lives in /etc/tmux.conf for a system-wide setup.
  • screen is installed everywhere, has simpler attach semantics and is what many older game guides assume. Its screen -L logging is genuinely useful.
  • Both buffer output in memory. A console that nobody reads for three days grows, and a server generating thousands of lines per minute during a wipe will consume tens of megabytes per session.

Whichever you choose, pin it. Half the node’s instances in tmux and half in screen is a runbook nightmare when the nightly Discord message says “server down” and nobody remembers which socket to attach to.

tmux basics for a game operator

# start a named session detached, run the game inside it
tmux new-session -d -s srv-rust1 \
  '/opt/rust/RustDedicated -batchmode +server.port 28015 +server.level Procedural'

# reattach from any SSH client
tmux attach -t srv-rust1

# list sessions, then detach without killing anything
tmux ls
# Ctrl-b then d

Two settings worth setting on a shared box immediately:

# /etc/tmux.conf
set-option -g history-limit 50000
set-option -g destroy-unattached off

history-limit sets how far back you can scroll a console. The default 2000 lines disappears the moment a save cycle logs its chunk write progress. destroy-unattached off prevents a session from dying if you ever start one without -d and lose the terminal.

screen basics, and why people still use it

screen -S srv-pal -L -Logfile /var/log/pal-srv.log \
  /opt/palserver/PalServer.sh -port=8211

screen -r srv-pal        # reattach
# Ctrl-a then d          # detach
screen -ls               # list

-L with -Logfile gives you console logging without a second tool, and often replaces the game’s own log file entirely. That is the strongest argument for screen on hosts that just want “console plus log, no extra moving parts”.

Send commands without attaching

The real value of a named console is automation: restart warnings, saves, whitelist reloads, without a human in a session.

# tmux: send a command and a newline into a session
tmux send-keys -t srv-rust1 'server.save' Enter

# screen: paste a command into the running session
screen -S srv-pal -p 0 -X stuff 'save\n'

Wrap these in small scripts and call them from cron or a systemd timer: a 5-minute warning broadcast at T-300, a save at T-60, the restart itself. This is the mechanism behind the automated backup and restart scheduling pattern, and it is far safer than a restart script that sends SIGKILL.

Note the trailing Enter for tmux and \n for screen. Getting that wrong produces a command sitting in the input buffer that fires with the next thing you type, which is a genuinely confusing failure mode.

Do not let tmux own the process lifetime

The temptation is to treat the tmux session as the supervisor: if the game crashes, restart it by sending a command. That works until the session is killed, the machine reboots, or someone types exit in the wrong pane. Then nothing restarts, and the node sits idle until a player complains.

The division that survives contact with reality:

  • systemd owns start, stop, restart-on-failure, boot ordering, resource limits and log capture.
  • tmux provides a console to the process systemd started, for interactive commands and for reading output.

If you want both, run a unit that starts the game inside a named tmux session with Type=forking or a wrapper script, and let Restart=on-failure handle crashes. The unit is still the supervisor; tmux is just the window.

The two-instances-one-lockfile failure

The most common self-inflicted outage on a game node: someone starts the server manually in a tmux session while systemd is also managing it. The second process fails on a port bind or a world lock, the first keeps running untracked, and the next systemctl restart stops the tracked process — which was never serving players — while the untracked one keeps the old world open.

Guard against it:

  • Before any manual start, run systemctl status and ss -lunp | grep <port>. Confirm nothing is listening.
  • Make manual starts an explicit, documented procedure with a matching manual stop, never an improvised ./start.sh.
  • Have the console send save and stop rather than killing the session, so the world closes cleanly.

The same discipline protects against save corruption, which is covered in save corruption and atomic writes.

Console buffers, memory and the OOM killer

A tmux session with a 50,000-line history per pane is not free. On a node running six instances, each with a chatty console, history buffers can add a few hundred megabytes — and they are invisible to the game’s own memory accounting. When the OOM killer picks a victim, it does not care that the memory belonged to a scrollback buffer.

Practical limits:

  • Keep history-limit at 10,000–50,000, not a million.
  • Enable the game’s own log file with rotation and let the console hold only recent output.
  • If a console is genuinely high-volume, redirect to a file with logrotate and keep the interactive session quiet.

Check real consumption with ps -o rss,cmd -C tmux and compare it against your RAM and disk metrics after a week, not after an incident.

Make consoles survive reboots, and survive you

The final piece is the runbook. Write down, in one file on the node and one in your notes:

  1. Session naming convention, e.g. srv-<game>-<slot>.
  2. The unit name and the console attachment command for each game.
  3. The save-then-stop sequence, and the warning schedule players expect.
  4. What to check first when a session exists but the port is not listening.

Then test it from a fresh SSH client with no history: attach to every session, confirm the game responds to a console command, confirm systemctl status agrees. A console you cannot reach at 2 a.m. is the same as no console.

The console layer is a small piece of operational maturity, but it is the piece that turns “someone’s SSH window” into infrastructure. If you are still choosing the machine underneath, our multi-game server hosting guide covers how many instances a node should carry, and panel scaling with Pterodactyl and Pelican is the natural next step once consoles and units are under control.

Running consoles under tmux is the low-effort version of process supervision; systemd units are the version that survives a reboot. Whichever you pick, the machine underneath decides how many instances you can hold — the dedicated plans table lists core counts and RAM per tier, and the main site explains which configs suit multi-instance hosting.

Leave a Reply