Beginner · 6 min · practise every command in the built-in terminal

Detaching and Reattaching

The whole point of tmux: leave a session running and come back to it later — even from a different SSH connection.

Detach from a session

Press Ctrl+b then d.

The session keeps running in the background; you're back at your normal shell.

Reattach later

tmux ls                    # See what's running
tmux attach -t work        # Reattach to it

Why this matters over SSH

If your SSH connection drops while running a command directly in the shell, that command dies. If it was running inside tmux, it keeps going — you just reattach when you reconnect.

Detach everyone else too

tmux attach -t work -d     # Attach here, detach any other client viewing it

screen — the older alternative

screen -S work        # Start named session
screen -ls             # List sessions
screen -r work         # Reattach
# Detach: Ctrl+a then d

tmux and screen solve the same problem; tmux is more actively developed and has nicer pane splitting, but you'll still see screen on older systems.

Practice tasks

  1. List tmux sessions to see what's running before reattaching
  2. Reattach to the 'work' session
  3. Attach to work while detaching any other client viewing it
  4. Kill the work session once you're finished with it

Commands in this lesson

tmux & Screen