4

I'm a bit of a tmux novice, so there may be a really easy answer to this question, but the title pretty much sums up the question.

Let's say I am ssh'd into a server in a tmux window and I go <prefix>-C. All of a sudden I have to ssh again, which can get annoying. Is there any way to automatically realise that I'm opening up another window from an ssh window already and run that same command in the new window automatically?

  • I just ssh first and then run tmux a || tmux on the server (actually this is in my .bashrc there). In my local terminal emulator usually I spawn one tab per machine and ssh accordingly. My local tmux has nothing to do with the remote one(s). I tend not to ssh to an interactive shell from within tmux. There are disadvantages but big advantages are: (1) If I'm on machine A, no tmux-related action will put me on B. (2) Remote tmux servers survive local reboots (compare this question and my answer there). – Kamil Maciorowski Oct 12 '19 at 22:10
  • When I first saw your question, I wasn't able to solve it. Few years later this one appeared: Is it possible to create a new pane with the same connection in tmux? I did not remember I had seen your question, I managed to solve the new one. To solve yours, I think it's enough to replace split-window with new-window in my answer there. – Kamil Maciorowski Sep 23 '23 at 21:53

1 Answers1

0

I came across your question many months ago and was looking for the same. I finally figured out how to accomplish part of your answer, which is the hardest part (split existing SSH). First install and configure SSHH (SSH Helper) to split the current SSH session into a new pane. Then, we can make it really fast by reusing the same ssh connection by adding this to our SSH config:

ControlMaster                  auto
ControlPath                    /tmp/ssh_mux_%h_%p_%r
ControlPersist                 4h # change to whatever you like, but 4h is a good start. 

Keep in mind that if our connection gets terminated we sometimes have to rm --force /tmp/ssh_mux_*. The tradeoff for superfast SSH splits is worth it!

Also, sshh doesn't work with Fish shell out of the box, but I figured out how to get it working, see https://github.com/yudai/sshh/issues/4.

Elijah Lynn
  • 1,514