IAnswerable

tmux Basics for Long-Running Server Tasks

06 Apr 2026

You SSH into a server, kick off a long migration, your laptop sleeps, the connection drops, and the process dies with it. tmux fixes this by running your session on the server, detached from your terminal entirely.

Install and start

apt install tmux    # Debian/Ubuntu
brew install tmux    # macOS, if you're testing locally

tmux new -s deploy

-s deploy names the session so you can find it later instead of guessing between 0, 1, 2.

The core workflow

  1. SSH into the server.
  2. tmux new -s deploy
  3. Run your long task — a migration, a build, a training job.
  4. Detach: Ctrl-b then d.
  5. Close your laptop, lose wifi, whatever. The process keeps running on the server.
  6. SSH back in later, reattach: tmux attach -t deploy

That’s the entire value proposition. Everything else is convenience on top. The session states:

stateDiagram-v2
    [*] --> Attached: tmux new -s deploy
    Attached --> Detached: Ctrl-b d
    Detached --> Attached: tmux attach -t deploy
    Attached --> [*]: exit or Ctrl-d
  

Essential keybinds

All tmux commands start with the prefix, Ctrl-b, released, then a key.

Action Keys
Detach Ctrl-b d
New window Ctrl-b c
Next/previous window Ctrl-b n / Ctrl-b p
Split pane vertically Ctrl-b %
Split pane horizontally Ctrl-b "
Switch pane Ctrl-b then arrow key
Kill pane Ctrl-b x
List sessions Ctrl-b s

Session management from outside tmux

tmux ls                    # list all sessions
tmux attach -t deploy      # reattach to one
tmux kill-session -t deploy

If you forget the name, tmux ls shows every session with how many windows it has and whether it’s currently attached.

The mistake everyone makes once

Closing the terminal window (or the SSH connection dying) without detaching first. tmux survives this fine — the session keeps running — but if you instead typed exit inside the tmux pane, you killed the shell running inside it, and the session with it. Ctrl-b d detaches; exit or Ctrl-d kills.

Rename a session you forgot to name

tmux rename-session -t 0 deploy

Run this from inside the session, or from outside with -t pointing at the old name.

A minimal config worth adding

Drop this in ~/.tmux.conf on the server:

set -g mouse on
set -g history-limit 10000
setw -g mode-keys vi

mouse on lets you click to switch panes and scroll with the trackpad — the default behavior without it is unusable if you’re not a keyboard purist. history-limit raises the scrollback from tmux’s stingy default so you don’t lose the top of a long build log.

tmux vs screen vs nohup

Persists past disconnect Reattach to see output Multiple windows/panes
nohup cmd & Yes No — output only in the log file No
screen Yes Yes Yes, clunkier keybinds
tmux Yes Yes Yes

nohup is fine for a single background command you don’t need to watch. The moment you want to check progress on something interactive — a build, a REPL, a log tail — you want tmux, not a redirected log file.

One habit worth building

Always name your sessions by task, not by number: tmux new -s db-migration, not tmux new. Six months from now, tmux ls showing deploy, logs, db-migration tells you something. 0, 1, 2 tells you nothing.