How do you detach from a tmux session?

tmux · Sessions · updated 2026-08-23

Ctrl + B, D — Detach client

Press the prefix Ctrl + B, release it, then press D to detach. The session keeps running in the background; tmux attach reconnects to it from any terminal.

Related tmux shortcuts: Sessions

ShortcutActionNotes
Ctrl + B, DDetach clientDetach the current client, leaving the session running in the background.
Ctrl + B, $Rename sessionRename the current session.
Ctrl + B, SChoose sessionSelect a new session for the attached client interactively.
Ctrl + B, (Previous sessionSwitch the attached client to the previous session.
Ctrl + B, )Next sessionSwitch the attached client to the next session.
Ctrl + B, Shift + LLast sessionSwitch the attached client back to the last session (uppercase L).
Ctrl + B, Shift + DChoose client to detachChoose a client to detach (uppercase D).
Ctrl + B, Ctrl + ZSuspend clientSuspend the tmux client.

From the tmux reference (73 entries) · all how-to answers

What detaching keeps

Detaching closes only the client — your terminal window — while the tmux server keeps every window and pane running with their processes. A build, a download or a long-running script continues after the SSH connection drops, which is the reason to start such work inside tmux in the first place. tmux ls lists the sessions still alive on the machine, and tmux attach -t name reconnects to a specific one from any terminal, including a different machine.

Detaching other clients

If a session is attached elsewhere — a laptop left open at the office — tmux attach -d detaches the other client as it attaches yours, and Ctrl + B, Shift + D opens a picker to detach a chosen client. A session attached from two clients of different sizes shrinks to the smaller one, which is why the picker exists.

Naming and cleaning up

Name sessions when you create them (tmux new -s deploy) so the list is readable a week later; Ctrl + B, $ renames the current one. Detached sessions accumulate on shared servers, so tmux kill-session -t name when the work is done, or tmux kill-server to remove everything.

Starting work so detaching is safe

Begin any job that must outlive the connection inside tmux from the start: tmux new -s build, run the command, detach. Reattaching later shows the scrollback as it was, including output produced while nobody was watching, and Ctrl + B, [ scrolls back through it. A job started outside tmux cannot be moved in afterwards without tools such as reptyr, so the habit is worth forming early.