Attach: tmux attach -t name. Detach: press Ctrl-b, then d. The session keeps running on the server after you detach, and attaching again puts you back on the same screen.
Below: finding the session name, creating and attaching in one command, what to do when the window is the wrong size, and reconnecting after an SSH drop.
List what's running first:
$ tmux ls
agents: 3 windows (created Wed Nov 11 09:14:02 2026) (attached)
logs: 1 windows (created Wed Nov 11 09:20:47 2026)
The name is the part before the colon. Then connect to the session by name:
tmux attach -t logs
attach is short for attach-session, and tmux a works too. Without -t, Tmux picks the most recently used session, preferring one that nothing else is attached to. Sessions you never named are numbered from 0, so tmux attach -t 0 attaches to the first unnamed one.
If no server is running, tmux ls reports that there's no server, which means there are no sessions to attach to.
To create a new session with a name:
tmux new -s work
Naming sessions makes attaching later a short command. The most useful form for daily use combines both jobs: -A attaches to work if it exists and creates it if it doesn't.
tmux new -A -s work
From a laptop, this opens SSH and lands in the session in one line. The -t gives SSH a terminal to run Tmux in:
ssh -t you@server tmux new -A -s work
tmux detach: the same, from a shell inside the session.tmux detach -s work: from anywhere on the server, detach every client attached to work.Detach and exit are different. exit closes the shell, and when the last shell in a session closes, the session ends. Detach when something should keep running; exit when you're done with it. To end a session from outside, tmux kill-session -t work.
A session can have several clients attached at once, say a laptop and a phone. By default each window is sized to the most recently active client, but older versions and some settings size it to the smallest, leaving dots around the edge on the bigger screen. To take the session over and detach everyone else:
tmux attach -d -t work
Running tmux attach inside a session gives "sessions should be nested with care, unset $TMUX to force". Switch instead:
| Keys or command | What it does |
|---|---|
| Ctrl-b s | Pick a session from a list |
| Ctrl-b ( / Ctrl-b ) | Previous / next session |
| Ctrl-b L | Back to the last session you were in |
tmux switch-client -t logs | Switch to a session by name |
When the SSH connection drops, the Tmux client goes with it, but the session is untouched: Tmux treats it as a detach. Whatever was running, a build, a log tail or an AI coding agent, keeps going.
tmux ls if you need the name.tmux attach -t name, or tmux new -A -s name to cover both cases.The session only disappears if the server reboots, someone kills it, or the last program in it exits.
On an iPhone or iPad the commands are the same; the keys are the awkward part. In Shell Drop:
set-titles lines from the cheat sheet to the server.The Tmux cheat sheet has the rest of the session, window and pane commands, and Tmux scrollback covers scrolling up once you're attached.
Run tmux ls to see the sessions, then tmux attach -t name with the session's name or number. tmux a attaches to the most recently used session, preferring one nobody else is attached to.
Press Ctrl-b, let go, then press d. The session keeps running on the server. From a shell inside Tmux, tmux detach does the same.
SSH back in and run tmux attach -t name, or tmux a for the most recent session. A dropped connection only detaches the session, so everything inside it kept running.
You ran tmux attach or tmux new from inside a Tmux session. Detach first and attach from a plain shell, or switch sessions from inside with Ctrl-b s or tmux switch-client -t name.
No. Detaching only disconnects your terminal. Programs keep running until they finish or the session is killed with tmux kill-session -t name.