12

I'm wondering if it's possible to share a tmux server socket between different hosts. For example, I have a virtual machine (guest) running inside my host, and I'm running a tmux session in the guest, is it possible for my host machine to access the guest's tmux session and do cool stuff with it? (e.g., sending commands over to the guest's session)?

1 Answer 1

12

A related topic came up on the tmux-users mailing list: Trying to use socat to tunnel tmux socket

Summary:

  • Simply forwarding the in-band, over-the-socket dialog between a tmux client and its server will not work because tmux uses file descriptor passing (the client passes its tty fd to the server).
    • It might be possible to develop a specialized proxy, but it seems like it would be non-trivial—it would need to know enough of the tmux socket protocol to know when to accept and send fds, and it would need a method of proxying the fds and any operations done on those fds.
  • The mailing list poster managed to work out a tmux forwarding system using socat that mostly worked.
    • You could probably set a different initial terminal size by giving the -x and -y options to new-session, but this would not fix resize handling (socat would need to handle and forward SIGWINCH (through TIOCGWINSZ/TIOCSWINSZ ioctls)).
    • It sounds like you might want your “forwarding server” to be in your guest OS, but the linked solution would make the server be in your host OS. You could probably rework it so it goes the other way around.

Unless there is some reason you can not run an SSH server on your guest, it is probably easier to use SSH to login to your guest (let the SSH programs handle connecting over the network and managing the ttys) and attach to (or issue commands to) the resident tmux that way:

host$ ssh guest tmux attach -t console
host$ ssh guest tmux new-session -s 'fiddling around'
# etc.

You can create an SSH key and ~/.ssh/config entries on your host to simplify the ssh command lines (i.e. using just ssh guest above instead of ssh -i guest-user1-key user1@guest-vm-ip).

2
  • I wonder if this could now be built using tmux control mode
    – mndrix
    Jan 13, 2017 at 19:36
  • @mndrix Did you just wonder or also ponder? Aug 6, 2020 at 5:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .