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?
Best Answer
(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.Your local tmux interprets it as the prefix key; nothing is sent to the processes running under the local tmux.
Your local tmux has it bound to the
send-prefix
command.Your remote tmux interprets it as the prefix key; nothing is sent to the processes running under the remote tmux.
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.