Two identical loops ran on a test container, each printing one line per second, each attached to a pseudo-terminal. Then the process holding each terminal was killed with kill -9, which is roughly what happens to the remote end of an SSH connection when Wi-Fi drops or a laptop lid closes. The loop in a plain shell stopped at “tick 4” and never wrote another line. The loop inside tmux was at “tick 34” two seconds later and still counting. Same command, same kill, and the only difference was which process owned the shell.
Why an SSH drop kills a running job
The shell belongs to the terminal, and the terminal just went away
When an SSH session ends, the pseudo-terminal it was driving closes, and the shell attached to it gets a hangup signal. The Bash manual’s section on signals says the shell “exits by default upon receipt of a SIGHUP,” and that before exiting, an interactive shell “resends the SIGHUP to all jobs, running or stopped.” That is why a half-finished rsync, a database restore or a long compile dies with the connection: the job was a child of a shell that was a child of the terminal, and the hangup traveled down the whole chain like a breaker tripping a row of circuits.
The test above reproduced it without SSH. On an Ubuntu 24.04 container, script provided a real pseudo-terminal, an interactive Bash ran a loop writing to a file, and kill -9 hit the script process:
plain shell after kill -9 of terminal holder: lines=4
3 s later lines=4
loop gone
nohup and disown exist to break that chain for one command. Tmux breaks it for everything, and keeps the screen.

What tmux actually runs
A server that owns the shells, and clients that only look at them
Tmux splits the job in two. The tmux(1) manual describes a single server that manages all sessions, with each client as a separate process, and states that “the server and each client are separate processes which communicate through a socket in /tmp.” The shells run under the server. The client is just a window onto them, attached to whatever terminal the SSH connection provides.
When the connection dies, only the client dies. The manual puts the whole value in one line: tmux “may be detached from a screen and continue running in the background, then later reattached.”
The container test, with tmux 3.4, ran the loop inside a detached session, attached a client through script, and then hung the client up:
$ tmux list-clients -F '#{client_tty}: #{session_name} (attached)'
/dev/pts/1: work (attached)
$ tmux list-clients # after hanging up the client
$ tmux ls -F '#{session_name}: #{session_windows} windows, #{?session_attached,attached,detached}'
work: 1 windows, detached
$ tmux capture-pane -p -t work | tail -3
tick 10
tick 11
tick 12
The client list went empty, the session flipped to detached, and the loop kept writing. A second run killed the script process with kill -9 instead of signaling the client directly, which is closer to a connection vanishing, and the session again survived: “work: detached,” loop at tick 34.
(The list commands above used -F format strings to keep the output short and free of timestamps. The test servers ran with -L lab, which the manual describes as choosing a named socket stored under TMUX_TMPDIR or /tmp. Separate sockets kept the experiments from touching each other.)
The four commands that cover most days
Start, detach, list, attach
The tmux Getting Started wiki notes that new-session “allows a name to be specified for the session with the -s flag.” Naming sessions is worth the extra keystrokes, because a list of sessions called 0, 1 and 2 tells nobody anything at midnight.
tmux new -s backup # start a named session
# ... run the long job ...
# press Ctrl-b, then d # detach; the job keeps running
tmux ls # list sessions
tmux attach -t backup # reattach from any later SSH loginEvery tmux key binding starts with a prefix. The manual gives it as “a prefix key, ‘C-b’ (Ctrl-b) by default, followed by a command key,” and d after the prefix will “Detach the current client.” Plain tmux attach with no target, per the wiki, attaches “to the most recently used session that is not already attached.”
One more option earns its place. If a session is still attached from a dead connection, or from a second machine, tmux attach -d -t backup takes it over; the manual says that with -d, “any other clients attached to the session are detached.” Without it, two clients share one session; the container’s tmux 3.4 reported window-size latest, which the manual describes as using the size of the client with the most recent activity.

Windows and panes
Tabs and split screens, both owned by the server
A session holds windows, and a window holds panes. After the prefix, c will “Create a new window,” % will “Split the current pane into two, left and right,” and " will split it “top and bottom.” The test session after one new window and two splits:
$ tmux list-windows -F '#{window_index}: #{window_name} (#{window_panes} panes)'
0: sleep (1 panes)
1: logs (3 panes)
$ tmux list-panes -t work:logs -F 'pane #{pane_index}: #{pane_width}x#{pane_height}'
pane 0: 60x30
pane 1: 59x15
pane 2: 59x14
The first window renamed itself “sleep” after the command running in it, which is tmux’s default automatic naming. A common layout for a home-lab box puts a long-running job in one pane, htop in another to watch the load figures explained in the load average post, and a free shell in the third for checks like the ones in finding what is using a port. All three survive a dropped connection together, since they all belong to the same server.
A minimal config, tested
Six lines, each one checked against the defaults it replaces
Before any config, the tmux 3.4 server on the container reported these defaults:
prefix C-b
history-limit 2000
mouse off
base-index 0
escape-time 500
The manual defines history-limit as “the maximum number of lines held in pane history” and escape-time as the time in milliseconds tmux waits after an Escape to decide whether it starts a longer key sequence. A 500 ms wait is noticeable in Vim, where Escape is pressed constantly. A small ~/.tmux.conf (the manual also accepts $XDG_CONFIG_HOME/tmux/tmux.conf):
set -g mouse on
set -g history-limit 50000
set -g base-index 1
setw -g pane-base-index 1
set -sg escape-time 10
bind r source-file ~/.tmux.conf \; display "config reloaded"
Loaded with tmux -f, the new server reported mouse on, history-limit 50000, base-index 1, escape-time 10, and its first window opened as index 1, which puts window 1 under the 1 key instead of making the leftmost key on the number row point at window 0.
The scrollback change is the one that pays off. In a pane on the default server, seq 1 5000 followed by a capture of the full history found the earliest surviving line was 3000. Everything before it was gone. The 50,000-line config kept all of it, back to line 1. That is the difference between reading the first error of a failed build and reading the last 2,000 lines of its consequences.
mouse on has a cost too. Per the manual, “tmux captures the mouse” when it is on, so clicks and drags go to tmux rather than to the terminal program, and copy-and-paste habits built on the terminal’s own selection may need relearning.

Where people get burned
Logout can kill the server, and some things were never going to survive
Systemd killing user processes at logout. The logind.conf(5) manual describes KillUserProcesses= as deciding whether a user’s processes “should be killed when the user logs out,” and the upstream text says it “Defaults to ‘yes’.” It also warns that this setting “will break tools like screen(1) and tmux(1),” unless they are moved out of the session scope, with an example pointed to in systemd-run(1). Distributions can ship a different default; the Ubuntu 24.04 container’s /etc/systemd/logind.conf lists #KillUserProcesses=no. On a box where a session that should persist vanishes at logout and not at a dropped connection, this setting is the first place to look.
Nesting by accident. Running tmux attach from a shell that is already inside tmux printed this on the test container:
sessions should be nested with care, unset $TMUX to force
One way to get there is a login script that auto-attaches, followed by an SSH hop from one such machine into another that does the same. Two layers of the same prefix key means every command gets eaten by the outer layer first.
Reboots. A tmux session is ordinary processes under a server. The Getting Started page notes that when no sessions, windows or panes remain, “the server will exit,” and a reboot ends the server along with everything else. Tmux protects against a dead connection. It does nothing for a dead machine, which is why scheduled work belongs in a timer, as covered in systemd timers vs cron, and not in a pane someone hopes to come back to.
Typing exit instead of detaching. exit in the last shell of the last pane closes the session, and the job inside goes with it. Detaching with Ctrl-b d leaves the door unlocked for the next login, while exit takes it off the hinges.
The case for not using tmux for this at all
Persistence is a side effect; the real fix might be elsewhere
A strong argument holds that a job important enough to need tmux is important enough to run as a proper service or a one-shot unit, with logs, restart rules and a record of its exit status. A pane in a detached session has none of those. If the job fails at 3 a.m., the only evidence is whatever text is still in scrollback, and only if the history limit was set high enough to hold it.
Other tools cover parts of the problem. Bash’s own disown -h, per the manual, marks a job “not to receive SIGHUP,” and nohup will “run a command immune to hangups.” Mosh, which describes itself as “a replacement for interactive SSH terminals,” says a laptop can sleep and wake “keeping your connection intact.” Its site also says Mosh “synchronizes only the visible state of the terminal” and suggests running screen or tmux on the remote side for scrollback. None of these gives back the screen itself, the half-typed command and the three panes exactly as they were, and that screen is the thing that goes missing when the connection drops.
Tmux is a landline in a building where the cell signal keeps cutting out. The call stays connected; it does not decide whether the call was a good idea. What is the longest a tmux session has stayed alive on one of your machines, and what finally killed it?
Sources
- GNU Bash Reference Manual, Signals: https://www.gnu.org/software/bash/manual/html_node/Signals.html
- tmux(1) manual page, man7.org: https://man7.org/linux/man-pages/man1/tmux.1.html
- tmux wiki, Getting Started: https://github.com/tmux/tmux/wiki/Getting-Started
- Mosh: https://mosh.org/
- nohup(1) manual page, man7.org: https://man7.org/linux/man-pages/man1/nohup.1.html
- logind.conf(5) manual page, man7.org: https://man7.org/linux/man-pages/man5/logind.conf.5.html
- x9m8, Linux load average explained: https://x9m8.com/linux-load-average-explained/
- x9m8, Find what is using a port on Linux: https://x9m8.com/find-what-is-using-a-port-linux/
- x9m8, Systemd timers vs cron: https://x9m8.com/systemd-timers-vs-cron/
