How to use tmux in this situation?

Hello there,

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.

Is there a way around this?

Give this a try… https://medium.freecodecamp.org/tmux-in-practice-local-and-nested-remote-tmux-sessions-4f7ba5db8795

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.

set -g prefix C-b
bind-key -n C-a send-prefix

1 Like

Many people start with some variant of this script called tmx that some guy on Gentoo forums shared.

It’ll reattach to an existing session or create a new one, and it’ll point ssh agent to a symlink that it’ll refresh from environment.

It’s very handy, try looking it up. Also, I find tmux man page a lot better than screen docs.

Thank you for the suggestions. The fixes are just too complicated.

I tried the double prefix as suggested, and over time that will just piss me off.

I gave up on having tmux on the gnome terminal, and use that terminal to ssh. Meanwhile on guake I use tmux for local system operations.

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.

Anyways, just thoughts, idk of this works.