2 minute read

use case: you need to connect to multiple hosts at once and leave the connections active even as you log out from the entry node.


network layout:

  • remote machine (e.g., laptop at home)
  • entry node (ssh gateway at work)
    • has tmux installed
  • multiple compute nodes

workflow for tmux session creation (only done once)

  1. ssh into entry node
  2. start tmux session (see config script below): $ tmux source ~/.tmux/nodes \; attach
  3. detach

workflow if tmux session is already started

  1. ssh into entry node
  2. attach tmux session
  3. select tmux pane/compute node
  4. run your stuff
  5. detach
  6. reattach session, ...

tmux config script to create a session with a 2x4 splitted terminal setup. upper row is logged into node{1..4} and changed into working directory. the lower row is logged into node{1..4} and shows stats using top.

[code language=text]
$ cat ~/.tmux/nodes

new-session -s nodes "ssh -t node1 'cd $SRC; zsh'"

split-window -h "ssh -t node3 'cd $SRC; zsh'"
split-window -h -t 0.0 -p 50 "ssh -t node2 'cd $SRC; zsh'"
split-window -h -t 0.2 -p 50 "ssh -t node4 'cd $SRC; zsh'"

split-window -v -t 0.0 "ssh -t node1 top"
split-window -v -t 0.2 "ssh -t node2 top"
split-window -v -t 0.4 "ssh -t node3 top"
split-window -v -t 0.6 "ssh -t node4 top"
[/code]

 

Tags:

Categories:

Updated: