5

The goal is to send tmux command to the local running tmux from the remote server. not to run to different instances of tmux.

Inside tmux we ssh to a server that doesn't run tmux

local>tmux send-key C-p  # works
local>ssh user@remote
user@remote> tmux send-key C-p # this will try to find tmux instance on remote. but we want to send it the local instead.

I can't use keybinding because this will run from inside script.

Nabil Sham
  • 267
  • 1
  • 2
  • 9

1 Answers1

0

No Linux Distro or version was specified so this answer assumes a relatively new version of SSH.

If the tmux "default" socket is being used on the local host but not on the remote host, tmux should just work by forwarding the unix socket from the remote host:

ssh -R/tmp/tmux-$UID/default:/tmp/tmux-${REMOTE_UID}/default remote

REMOTE_UID should be set manually to the UID of the remote user but UID is usually set automatically in the environment.

Ideally, a unique (non-default) tmux socket name should be chosen to avoid conflicts:

local> tmux -L foo
remote> ssh -R/tmp/tmux-$UID/foo:/tmp/tmux-${REMOTE_UID}/foo remote
remote> tmux -L foo send-key C-p

Playing around with TMUX_TMPDIR environment might give a more transparent and polished experience and work around having to know the UID but that depends on the requirement and might be overkill for just a script.

Mario
  • 31
  • 4
  • Are you sure this works? I've read that you can't connect tmux sockets... – Boris Churzin May 12 '18 at 07:57
  • It works on my systems (Devuan ASCII, CentOS 7). What do you mean by "you can't connect tmux sockets"? Why not try it and leave some useful feedback? – Mario May 14 '18 at 08:09
  • https://github.com/tmux/tmux/issues/462 – Boris Churzin May 14 '18 at 12:12
  • Also, rudeness is not appreaciated in this community, I just asked if you are sure (read: tried it or is it a guess), "It works on my systems" would be enough... I don't currently have access to any machine to check, once I do I'll leave feedback. – Boris Churzin May 14 '18 at 12:20
  • @Devenv: No one is rude here. – Sven May 14 '18 at 12:31
  • @Devenv: Not trying to be rude. I'm sorry if you interpreted that way. Was just asking you to just try it if in doubt and submit your findings which would have either supported or contradicted mine. That would be more useful to the op. – Mario May 15 '18 at 10:10
  • 2
    @Devenv: https://github.com/tmux/tmux/issues/462 is related to a socket over a shared directory. The story is different for SSH forwarded Unix sockets since SSH works as a "proxy" and just forwards requests which should work in most cases (unless MSG_OOB or some other system-specific OOB functionality is required.) – Mario May 15 '18 at 10:16
  • Yepm works, thanks you. Doesn't help my issue directly (unrelated to OP question), but I can work something out of it :) – Boris Churzin May 19 '18 at 09:16