TL;DR: I use tmux as my default shell, but when I ssh into a machine I also want to use tmux. Now I have two tmuxes running and only the host tmux is functional. What to do?
I have tmux as my custom shell for my terminals but when I ssh into a remote machine I don’t retain tmuxes functionalities. I have tried running tmux after ssh’ing but I end up with two green tmux bars at the bottom of the terminal and the remote one is ignored; this means all tmux commands get passed to the local host one and not the remote one where I want to do stuff or think I want to.
First of all, you face the question: How you can control inner sessions, since all keybindings are caught and handled by outer sessions?
The most common solution is to press prefix twice (prefix is a keybinding that puts tmux in a command mode, usually it’s C-b, but some people prefer remapping it to screen-likeC-a). The first prefix keystroke is caught by the outer session, whereas second is passed to the inner session. No extra steps need to be done, and this works out of the box.
However, root keybindings those which are listened globally, not in command mode are still caught by the outer session only. And I found it’s really annoying to double press prefix. For me it’s even annoying to press it once, in iTerm2 there is no such thing as command mode, and I just press “⌘⌥→” to select pane on the right, instead of sending two separate keystrokes C-a RightArrow.
Another solution is to setup 2 individual prefixes, for example, C-b for a local session, while C-a for a remote one. With the configuration below, it means that pressing C-a locally would send default prefix C-b to the remote session. Found this solution here.
You could tunnel the tmux socket with socat amd attach to it locally, then prefix+s to switch between sessions. Idk how secure that is.
You could also create a new local session and give it a default-command to connect to ssh, if you’re using keys and have a key agent you should be askes the passwd only once.