>_ josetilabs.com
← blog

04 Nov 2026 · linux, terminal · 4 min

tmux: survive an SSH disconnect

tmux runs a server separate from the terminal you see. When the SSH connection drops, the client dies, not the server, and the session keeps running with everything inside it. To get back, just reattach with tmux attach. I tested dropping the client and reattaching: tmux 3.4 preserved the full scrollback (HELLO_TMUX_PROVA, kernel and date) in under a second.

What survives the drop

tmux splits the work into two processes. The server holds the sessions, windows and panes. The client is just the screen you look at. When SSH drops, the client dies; the server does not notice. The session keeps running in the background, including long jobs like apt upgrade or rsync. On reconnect, tmux attach puts you back inside it, with scrollback intact.

This differs from leaving a process with nohup or disown. With nohup, the output is lost and you can no longer interact. With tmux, you get the screen back exactly as it was, cursor position included.

The .tmux.conf I use

A short, commented file that runs from scratch. The block below writes it and, if tmux exists in the environment, reloads the configuration.

bash
#!/usr/bin/env bash
set -euo pipefail

FILE="${TMUX_CONF:-$HOME/.tmux.conf}"

cat > "$FILE" <<'EOF'
# Prefix: Ctrl-a instead of Ctrl-b, easier to reach
unbind C-b
set -g prefix C-a
bind C-a send-prefix

# Numbering starts at 1, like the keyboard
set -g base-index 1
setw -g pane-base-index 1
set -g renumber-windows on

# Large scrollback so output is not lost
set -g history-limit 100000

# Mouse on for scrolling and resizing panes
set -g mouse on

# Colors and a simple status line
set -g default-terminal "screen-256color"
set -g status-left "[#S] "
set -g status-right "%H:%M"
set -g status-interval 5

# Split panes with | and -
bind | split-window -h
bind - split-window -v
unbind '"'
unbind %

# Reload config with prefix + r
bind r source-file ~/.tmux.conf \; display "config reloaded"
EOF

echo "written: $FILE"

if command -v tmux >/dev/null 2>&1; then
    tmux source-file "$FILE" 2>/dev/null && echo "config reloaded into running server" \
        || echo "no server running; config applies to the next session"
else
    echo "tmux not found in this environment; install it, then run: tmux source-file $FILE"
fi

Session, window, pane

Three levels, from largest to smallest. A session is a project. A window is a tab. A pane is a split of the screen.

bash
# create a named session
tmux new -s work

# detach (leaves it running in the background)
# prefix + d, or:
tmux detach-client -t work

# list and reattach
tmux ls
tmux attach -t work

# new window and navigation
tmux new-window -n logs
tmux select-window -t 2

# split the current screen
tmux split-window -h
tmux split-window -v

To copy text from scrollback, enter copy mode with prefix + [, scroll with the arrows and press space to start the selection. q exits.

How to verify

Create a session, run a command that prints something, drop the client and reattach. The scrollback must still be there.

bash
tmux new-session -d -s proof -n shell
tmux send-keys -t proof 'echo PROOF_TMUX; uname -sr; date -Is' C-m
sleep 1
tmux detach-client -t proof
tmux ls
tmux attach -t proof

Expected output: the proof session is still listed after the detach, and tmux attach shows PROOF_TMUX, the kernel and the date. If the session does not appear in tmux ls, the server died with the client and the configuration was not loaded.

If it goes wrong

tmux, screen or zellij

Tool License When to use
tmux ISC Default on servers; present in every repository
screen GPL-3 Only if it is already there and you cannot install
zellij MIT Modern terminal with ready-made panes, needs an extra binary

Frequently asked questions

Does tmux survive a reboot? No. The server dies with the machine. To persist sessions across reboots, use tmux-resurrect or recreate them from a script on boot. For long jobs that must not stop, prefer systemd.

Can two people share a session? Yes, with tmux attach -t name in two terminals. Both see and type on the same screen.

How do I kill a stuck session? tmux kill-session -t name. If the whole server is stuck, tmux kill-server.

Does tmux work inside Docker? Yes, but it needs a TTY. Run with docker run -it or use docker exec -it.

Measurement

In the test, the proof session was still listed after the detach and the reattach showed PROOF_TMUX, the kernel and the date. The time between detach and reattach was under a second. This confirms the server does not depend on the client. The preserved scrollback included the command line, the output and the prompt.

The official man page at man.openbsd.org/tmux lists every command and option. The code and release notes for 3.4 are at github.com/tmux/tmux.

Terminal mostrando sessão tmux criada, cliente derrubado, reattach e o histórico anterior ainda visível
A sessão segue viva depois da queda do cliente e o histórico é recuperado no reattach.

Sources

Official tmux man page at man.openbsd.org/tmux (consulted 04 Nov 2026). Repository at github.com/tmux/tmux (tmux 3.4). Internal links: /en/blog/cron-do-jeito-certo.html, /en/blog/ssh-agente-como-parar-de-digitar-a-senha.html, /en/blog/terminal-que-parece-limpo-e-funciona.html, /en/blog/journalctl-para-achar-o-erro.html.

Read next

// By e-mail

Posts published here also go out by e-mail. Delivery has not started yet: whoever leaves an address now joins the first batch.

I store only your e-mail, the date and the record of this consent. No cookies, no trackers, nothing shared with third parties. Details in the privacy policy.