Just a brief description of how I use tmux to ssh into multiple ec2 instances running on AWS ASG from my Mac
- Install homebrew from https://brew.sh/
brew install fish
brew install jq
brew install tmux
gem install tmuxinator
. (If you don't like tmuxinator, you may try out Teamocil or tmuxp. However, the below code is based on tmuxinator yaml)- Create the below tmuxinator file
# ~/.tmuxinator/dynamic-ssh.yml
name: dynamic-ssh
root: ~
windows:
- win1:
layout: tiled
panes:
<% @args.each_with_index do |machine, idx| %>
- pane<%= idx + 1 %>:
- ssh <your-ssh-user>@<%= machine %>
<% end %>
If you frequently connect to new hosts and want to avoid specifying yes everytime, you can add -o StrictHostKeyChecking=no
to your ssh command. More info here
- Create the below fish function
# ~/.config/fish/functions/launch.fish
function launch
tmuxinator start dynamic-ssh ( curl "{API-URL-to-get-JSON-array-of-ec2-instance-name}" | jq -r 'join("\n" )' )
end