I've opened a tmux session on my local machine, and ssh to the remote machine. After this, I typed command "tmux attach" on the remote machine, then I got a remote tmux session on my local tmux session.

Now I want to detach the remote tmux sesstion, I've tried

C-b d

but it detached my local tmux session rather than the remote one.

How can I detach the remote tmux sesstion?

6 Answers 6

C-b C-b d

(assuming default bindings)

The first C-b is interpreted by your local tmux (because it is the first to see all your keystrokes). The second C-b is a command that causes your local tmux to send a C-b to its active pane; this generated C-b arrives at the remote tmux. The d passes through the local tmux unchanged; when it gets to the remote tmux it triggers the detach command.

  1. You type C-b.
    Your local tmux interprets it as the prefix key; nothing is sent to the processes running under the local tmux.
  2. You type C-b.
    Your local tmux has it bound to the send-prefix command.
    1. Your local tmux sends a C-b to the process running in the active pane (ssh).
    2. ssh forwards it (through sshd, etc.) to the process running on the remote end (remote tmux).
      Your remote tmux interprets it as the prefix key; nothing is sent to the processes running under the remote tmux.
  3. You type d.
    Your local tmux passes it through normally (since the second C-b finished a full command key sequence for the local tmux).
    Your remote tmux has it bound to detach-client; it detaches the active client.

This is the same as when you need to send a C-b to any program running inside a tmux session. If you wanted to send C-b to your normal shell (e.g. because your shell is using Emacs-style editing where C-b is backward-char (and you dislike using the arrow keys)) you would need to use C-b C-b to get a single C-b to the shell.

  • 9
    Alternatively, I've frequently seen the use of C-a C-a to jump to the last active window. Under such circumstances try C-a a d to detach. Thanks!
    – mkelley33
    Oct 25, 2013 at 0:31
  • 2
    Note: the combo I mention above would only be available if the a key is bound instead of b in the user's tmux.conf.
    – mkelley33
    Oct 25, 2013 at 0:42
  • My outer tmux uses C-a and the inner one C-b, and to be able to detach from the inner one the only thing that works for me is C-a C-b-b d, but I don't get why do I need the second b Aug 21, 2018 at 15:10
  • Just a reminder to allow folks to enable this option if they don't have default keybindings: you can run the : command to run a tmux command interactively, and then set up a binding via the bind-key -n j send-prefix command. In this example I wanted to bind j to send the prefix. Otherwise, use Dave's answer: use the tmux detach command.
    – nealmcb
    Jul 10, 2019 at 20:15
  • On Mac it was command + b then d to detach the tmux session.
    – Ryan Gates
    Dec 17, 2020 at 22:01

Another way to do it without worrying about the keybindings making it to the right tmux instance is to type tmux detach in the remote tmux session.


I tried the first answer without success.

I was able to get the results I wanted by doing the following:

tmux attach

I entered tmux and saw the other session was still attached

So I detached my current session to get back to a shell: Ctrl + b; d

Then I issued the following: tmux attach -d

This says to attach to the default session, and detach all other sessions currently attached. See the man page under Clients and Sessions

attach-session [-dr] [-t target-session] (alias: attach) If run from outside tmux, create a new client in the current terminal and attach it to target-session. If used from inside, switch the current client. If -d is specified, any other clients attached to the session are detached. -r signifies the client is read-only (only keys bound to the detach-client command have any effect)


If you want to try an other option follow below steps

  1. detach current tmux session with Ctrl+b d . So that you now you go to normal terminal command line prompt.
  2. Do a tmux ls . Look for session that is currently attached
  3. Execute this command to detach the already attached session tmux detach-client -s <attached_session_name>

If you have modified your tmux config to use something other than Ctrl+b in both tmux sessions you still need to press Ctrl+b the second time.

For example my binding is Ctrl+/ in both tmux sessions so I press:

C-/ C-b d

You can use ctrl+b d to detach and ctrl+b s to see all sessions, ctrl+b c to open a tmux session inside a tmux session

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.