tmux cluster ssh to multiple ec2 instances
- AWS access
- EC2 only to DescribeInstances
- ECS functionality requires:
- Private ssh keys for the servers you will try to connect to in
~/.ssh
- file in your
${PATH}
- tmux-cssh in your
${PATH}
- poetry
poetry install
$ cd /path/to/this/repository
$ AWS_PROFILE=my-aws-profile poetry run python ./ec2-tmux-cssh.py --use-bastion
[?] What tag_key should I use to find instances?: Name
> Name
Role
aws:autoscaling:groupName
aws:cloudformation:logical-id
aws:cloudformation:stack-id
aws:cloudformation:stack-name
aws:ec2launchtemplate:id
aws:ec2launchtemplate:version
[?] What Name value should I use to find instances?: qa-ecs-cluster
> qa-ecs-cluster
rabbitmq
ecs-cluster
[?] Which private key should I use for the hosts?: /Users/macuser/.ssh/qa.pem
+ README
/Users/macuser/.ssh/id_ed25519
/Users/macuser/.ssh/prod-bastion.pem
/Users/macuser/.ssh/prod.pem
/Users/macuser/.ssh/qa-bastion.pem
> /Users/macuser/.ssh/qa.pem
[?] Which ssh user should I use for the hosts?: ec2-user
centos
> ec2-user
ubuntu
[?] What tag_key should I use to find bastions?: Role
Name
> Role
aws:autoscaling:groupName
aws:cloudformation:logical-id
aws:cloudformation:stack-id
aws:cloudformation:stack-name
aws:ec2launchtemplate:id
aws:ec2launchtemplate:version
[?] What Role value should I use to find bastions?: bastion
DB
> bastion
[?] Which bastion should I proxy through?: qa-bastion
prod-bastion
> qa-bastion
stage-bastion
[?] Which private key should I use for the bastion host?: /Users/macuser/.ssh/qa-bastion.pem
/Users/macuser/.ssh/id_ed25519
/Users/macuser/.ssh/prod-bastion.pem
/Users/macuser/.ssh/prod.pem
> /Users/macuser/.ssh/qa-bastion.pem
/Users/macuser/.ssh/qa.pem
[?] Which ssh user should I user for the bastion host?: ubuntu
centos
ec2-user
> ubuntu
I will tmux-cssh through bastion qa-bastion to these IPs: ['10.10.21.104', '10.10.21.230', '10.10.21.223', '10.10.20.118', '10.10.20.83', '10.10.20.39']
* Connecting 'ssh -o ProxyCommand='ssh -i /Users/macuser/.ssh/qa-bastion.pem ubuntu@SomePublicIP -W %h:%p' -i /Users/macuser/.ssh/qa.pem [email protected]'
* Connecting 'ssh -o ProxyCommand='ssh -i /Users/macuser/.ssh/qa-bastion.pem ubuntu@SomePublicIP -W %h:%p' -i /Users/macuser/.ssh/qa.pem [email protected]'
* Connecting 'ssh -o ProxyCommand='ssh -i /Users/macuser/.ssh/qa-bastion.pem ubuntu@SomePublicIP -W %h:%p' -i /Users/macuser/.ssh/qa.pem [email protected]'
* Connecting 'ssh -o ProxyCommand='ssh -i /Users/macuser/.ssh/qa-bastion.pem ubuntu@SomePublicIP -W %h:%p' -i /Users/macuser/.ssh/qa.pem [email protected]'
* Connecting 'ssh -o ProxyCommand='ssh -i /Users/macuser/.ssh/qa-bastion.pem ubuntu@SomePublicIP -W %h:%p' -i /Users/macuser/.ssh/qa.pem [email protected]'
* Connecting 'ssh -o ProxyCommand='ssh -i /Users/macuser/.ssh/qa-bastion.pem ubuntu@SomePublicIP -W %h:%p' -i /Users/macuser/.ssh/qa.pem [email protected]'
[exited]
$ poetry run python ec2-tmux-cssh.py --help
Usage: ec2-tmux-cssh.py [OPTIONS]
Options:
--is-ecs Find ec2 instances where ecs service runs on
--ecs-cluster TEXT ECS Cluster where ECS Service runs on
--ecs-service TEXT ECS Service we want to find EC2 instances for
--hosts-tag-key TEXT Tag key to find hosts with
--hosts-tag-value TEXT Tag value to find hosts with
--hosts-ssh-key TEXT SSH Private Key for hosts
--hosts-user TEXT SSH user for hosts
--use-bastion Proxy SSH through a bastion host
--bastions-tag-key TEXT Tag key to find bastions with
--bastions-tag-value TEXT Tag value to find bastions with
--bastion-name TEXT Bastion EC2 Name
--bastion-ssh-key TEXT SSH Private Key for bastion
--bastion-user TEXT SSH user for bastion
--help Show this message and exit.