To attach to a tmux session, use tmux attach
or tmux a
. To attach to a specific session, use tmux attach -t session-name
.
$ tmux attach -t mysession
The tmux attach command connects you to an existing tmux session. This is one of tmux's core features - the ability to detach from a session and reattach to it later, even from a different computer or terminal.
tmux attach
or tmux a
- Attach to the most recently used sessiontmux attach -t session-name
- Attach to a specific session by nametmux attach -t 0
- Attach to a session by numberIf you have multiple sessions, first list them to see which one you want to attach to:
$ tmux ls 0: 1 windows (created Fri May 31 12:34:56 2025) [80x24] dev: 2 windows (created Fri May 31 14:10:34 2025) [80x24]
Then attach to your desired session:
$ tmux attach -t dev
tmux attach -d
- Attach and detach all other clients (useful for screen sharing)tmux attach -r
- Attach in read-only modetmux attach -c /path
- Set the working directory for the session If the session doesn't exist, you'll get an error. Use tmux new-session -A -s name
to create the session if it doesn't exist or attach if it does.
When connecting to a remote server, you can automatically attach to a tmux session with: ssh user@host -t tmux attach