A tmux Setup for Long Running Servers and Log Tails
I lost a Valheim world to a dropped SSH connection. Not corrupted, just gone: the server process had been started in a plain shell, my train went into a tunnel, the session died, and the world file was last written eleven minutes earlier.

I lost a Valheim world to a dropped SSH connection. Not corrupted, just gone: the server process had been started in a plain shell, my train went into a tunnel, the session died, and the world file was last written eleven minutes earlier. Six friends had been building a dock. I rebuilt it badly and nobody said anything.
That is the problem tmux solves, and the reason almost everyone who runs a server from a laptop ends up learning it. It keeps a shell alive on the machine rather than inside your connection, so you can disconnect, close the lid, change networks, and attach again to find the same running process and the same scrollback. The learning curve is about twenty minutes, and most of what gets written about it buries those twenty minutes under a hundred key bindings.
The four commands that cover most days
tmux has an enormous surface and you can ignore nearly all of it. Four commands and one key combination will carry you through a year.
Start a named session with tmux new -s gs, where gs is whatever you want to call it. Names matter more than they look like they do, because tmux new on its own gives you sessions called 0, 1 and 2, and by Thursday you will not know which holds the thing you care about.
Detach with Ctrl-b then d. The session keeps running. List what is alive with tmux ls, which prints each session name, window count and whether anyone is attached. Reattach with tmux a -t gs.
That is the whole core loop. Start named, detach, list, attach. If you learn nothing else, you still never lose a process to a tunnel again.
Two more worth having on day one. Split the current pane side by side with Ctrl-b then the percent key, or top and bottom with Ctrl-b then the double quote key, and move between panes with Ctrl-b and an arrow key. I keep a server console on the left and a log tail on the right, which is the layout I have used for about six years without changing it.
A config file short enough to read
The default prefix, Ctrl-b, is awkward on most keyboards and sits next to nothing useful. Almost everyone remaps it to Ctrl-a, which conflicts with the shell shortcut for jumping to the start of a line, so you also bind the prefix twice to send it through. My entire ~/.tmux.conf is nine lines.
unbind C-bandset -g prefix C-ato move the prefix, thenbind C-a send-prefixso pressing it twice still reaches the shell.set -g mouse on, which lets you click between panes, drag the divider and scroll the buffer with a wheel. Purists dislike it. I have never regretted it on a machine I am troubleshooting at two in the morning.set -g history-limit 50000, because the default of 2000 lines will not hold the output you wanted to read when something crashed.set -g base-index 1andsetw -g pane-base-index 1, so window numbering starts where the keyboard does.set -g status-right "#H %H:%M"to put the hostname in the corner. Cheap insurance against running a command on the wrong box.setw -g automatic-rename off, so a window you named stays named instead of turning into whatever process is in the foreground.
Reload it inside a running session with Ctrl-b then colon, then source-file ~/.tmux.conf. No restart, no lost sessions.
Scrollback, and the one thing that confuses everybody
Pressing the up arrow or scrolling in a tmux pane does not do what you expect, and this is the point where people decide the tool is hostile.
tmux has its own copy mode. Enter it with Ctrl-b then the open bracket key, move with arrows or Page Up, and leave it with q. Search backwards through the buffer with Ctrl-r inside copy mode, which is how you find the stack trace that scrolled past while you were reading something else. With mouse mode on, a wheel scroll enters copy mode automatically and exits when you reach the bottom.
The related trap: text selected in copy mode goes to the tmux clipboard, not your system one. Over SSH there is no clean fix that works everywhere. What I do instead is write the output to a file and read it locally, because fighting clipboard integration across a network boundary has cost me more hours than it ever saved.
Where I disagree with the standard advice
The usual framing is that tmux is how you run long lived processes on a server. I used to repeat that. Then I spent a Sunday explaining to a group of players why their world had been offline since Friday, and the answer was that the host had rebooted for kernel updates and no tmux session survives a reboot.
So here is the line I now draw. tmux is for interactive work: watching a migration run, tailing logs while you poke at something, keeping a shell open during a long build. If a process is supposed to be running tomorrow whether or not you are awake, it belongs in a service manager, not a terminal multiplexer.
A systemd unit for the same game server is about fifteen lines, restarts the process if it dies, starts it again after a reboot, and writes output somewhere you can query later. Writing that unit takes longer than typing tmux new, which is exactly why people keep choosing the worse option, and I did it for two years myself.
There is an in between case I will defend. For a server that one person babysits and restarts by hand anyway, with a world file that needs a manual backup between sessions, tmux plus a reminder is honestly fine. Just know which situation you are in, and do not let a weekend experiment quietly become infrastructure that six people depend on.
Picking up where you left off
The habit worth building is one session per job, named after the job. I keep gs for the game server, logs for anything I am watching, and work for the current task. When a session no longer has a purpose, close it with tmux kill-session -t name rather than letting eleven dead sessions accumulate, each holding a shell in a directory you no longer remember.
If you work across several machines, the SSH config file setup pairs well with this, since a short alias plus an attach command gets you back into context in one line. And for anything you want running reproducibly rather than interactively, the approach in Docker Compose for local development solves a similar problem from the other direction. More workflow pieces sit in the dev tools section.
FAQ
Is tmux better than screen?
For new setups, yes, mostly because the configuration is far easier to read and panes work properly. If a server already has a screen session you understand, there is no urgency. Both survive a disconnection, which is the part that matters.
Do tmux sessions survive a reboot?
No. Everything inside them dies with the machine. Plugins exist that save and restore layouts, but they restore the windows, not the processes that were running in them.
Why does my shell prompt look wrong inside tmux?
Usually a terminal type mismatch. Set set -g default-terminal "tmux-256color" in the config, and if colours still look flat, check that your local terminal advertises 256 colour support before blaming tmux.
Can two people attach to the same session?
Yes, and it is a decent way to pair on a problem. Both see the same screen and both can type, so agree out loud who has the keyboard. Attaching with the -d flag instead kicks the other person off, which is rude but occasionally necessary.
More in Dev Tools
Dev Tools
Git includeIf Setup for Work and Personal Identities
The commit that made me fix this properly had my personal address on it, sitting in a client repository, pushed to a branch...
Dev Tools
Sign Git Commits With an SSH Key in Fifteen Minutes
Anyone can set their Git name and email to yours. It takes one line of config, no password and no access to your accounts, and...
Dev Tools
Git Bisect to Find the Commit That Broke Your Build
The build passed on Monday and fails on Thursday, and there are 140 commits in between.