Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass command keys to a remote tmux session when you SSH from a local tmux session into a remove tmux session [duplicate]

Tags:

linux

ssh

tmux

I would like to use my ssh tmux session inside my development tmux session, but it makes tmux behave bad (keys go to wrong session, etc). Is there a way to do it properly?

like image 228
Sławosz Avatar asked Jul 29 '13 09:07

Sławosz


People also ask

What command combination will detach your terminal from a running tmux session?

To detach (meaning exit the window to come back to later) from the tmux session, use CTRL + b then d (hold ctrl, press b, let go of both of the keys, and press d). Whatever program(s) you are running in the tmux session will continue going without you.

How do you enter commands in tmux?

To enter Command mode, press Prefix : (the colon) from within a running tmux session. The status bar changes color and we get a command prompt that indicates that we can type our command.

Does tmux work over SSH?

With tmux you only need one SSH connection to the server. The great thing about tmux is it allows you to have multiple panes open at the same time, each with their own shell running, but using the same, single SSH connection.


2 Answers

You can set up

bind-key b send-prefix

in your .tmux.conf. By default all commands go to the outermost tmux session. If you press <prefix-key>b (<prefix-key>=ctrlb by default) the commands go to the inner session. Here an example:

ctrl-b   c  # create new window in the outer session
ctrl-b b c  # create new window in the inner session
ctrl-b   %  # create split window in the outer session
ctrl-b b %  # create split window in the inner session
like image 172
Marco Avatar answered Sep 21 '22 20:09

Marco


At least on my machines, I need to press "the key" (prefix-key) twice, to get a command to the tmux inside the base tmux,

So if I from a tmux window, I ssh into a server and attach to a tmux session as @Marco described above, I need to do these:

ctrl-b-b c # create a new window on the server (remote tmux)
ctrl-b   c # create a new window on my desktop (local tmux)

to make is super clear, ctrl-b-b means hold down ctrl press b twice then release and press the command key, c in the example above.

like image 27
Ali Avatar answered Sep 20 '22 20:09

Ali