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.

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