2020-09-09

Quick setup script with tmux

In my network security class we ssh into a handful of VMs pretty often.
Instead of trying to juggle 5 open terminal windows I tried to make this a bit easier to manage by having all my ssh sessions run in separate tmux windows - switching between them with C-b {1,2,3,etc} when necessary. I found myself doing this every time I’d load up my Kali Linux VM:

tmux
C-b c
ssh bastion
C-b c
ssh proxyserver
C-b c
ssh edgerouter

But then I thought, why not script this process? It should be easy enough. And it sure was easy. Here’s what I came up with:

#!/bin/sh

tmux new-session -d
tmux new-window -n "bastion" ssh bastion
tmux new-window -n "proxyserver" ssh proxyserver
tmux new-window -n "appserver" ssh appserver
tmux new-window -n "edgerouter" ssh edgerouter
tmux selectw -t 0

tmux attach-session -d

First, the script creates a new tmux session in the background. Then it opens a new window for each ssh session, naming them appropriately. After that it switches back to the first window (which is just a local shell), and finally it attaches the tmux session to the current terminal session.

Now after I start my VM all I have to do is run the script (I called it setupsess), and I’m ready to start hacking away at my messy nftables configs.