Tmux Session Management: Create, List, Attach, Detach, End & Quit

l9c l9c

TL;DR — Start a session with tmux new -s mysession, detach with Ctrl+b then d, list with tmux ls, return with tmux attach -t mysession, and end it with tmux kill-session -t mysession.

What a tmux session actually is

A tmux session is a workspace owned by a background tmux server. Every window and pane lives inside a session, and the session keeps running after you close the terminal or drop an SSH connection. This is why tmux is the standard tool for long-running work on remote machines.

Session commands at a glance

TaskCommand
Create a session
tmux new-session
Create a named session
tmux new-session -s mysession
Create detached (no terminal attached)
tmux new-session -d -s mysession
List sessions
tmux list-sessions   # shortcut: tmux ls
Attach to an unattached session
tmux attach
Attach to a named session
tmux attach -t mysession
Detach from inside tmuxCtrl+b then d
Kill one session
tmux kill-session -t mysession
Kill every session (and the server)
tmux kill-server

See session management in action

The recording starts at a shell prompt in an empty ~/example directory: it creates a named session, detaches with Ctrl+b d, lists the session from the shell, reattaches, then ends one session with kill-session and everything with kill-server.

Frequently asked questions

How do I list tmux sessions?

Run tmux ls, the shortcut for tmux list-sessions. It prints one line per session with the window count and whether a client is attached. Use tmux ls -F with format strings such as #{session_name} when you only need specific fields.

How do I create a named tmux session?

Run tmux new -s mysession (long form: tmux new-session -s mysession). It creates the session and attaches your terminal to it. Add -d to create it detached, for example tmux new -d -s logs when a background job should keep running.

What is the difference between detaching and killing a session?

Detaching (Ctrl+b then d, or tmux detach-client) disconnects your terminal while the session and every program inside it keep running. Killing (tmux kill-session -t mysession) destroys the session and its unshared windows, with no confirmation and no way to undo it.

Why did my tmux session disappear?

A session ends when its last pane closes (typing exit or pressing Ctrl+d in the final shell), when it is killed with kill-session, or when the server stops, for example tmux kill-server or a reboot. Detaching or losing SSH normally leaves the session running.

How do I rename a tmux session?

From inside it, press Ctrl+b then $ and type the new name, or run tmux rename-session newname. From a shell, name the target explicitly: tmux rename-session -t mysession newname.

Can two clients attach to the same session?

Yes. tmux attach -t mysession from a second terminal adds another client to the same session, and both terminals see the same windows. Use tmux attach -d -t mysession to take the session over and detach other clients.

Keep going with the full list in tmux commands and build a starting config with the tmux config generator.