Skip to content

How to run cluster ssh on MacOS

sorrachai edited this page Jan 23, 2018 · 7 revisions

Goal

To run identical commands on multiple EC2 instances simultaneously via ssh.

Instructions

  1. We need to use a common public key for each instance. This setup allows us to run cluster ssh on multiple regions, see also reference [1]. To setup for AWS-instances:
  1. Install csshx, Cluster SSH tool for MacOS. Follow https://github.com/brockgr/csshx.

How to use

run the following command:

./csshX --ssh_args '-i path-to-private-key/your_private_key -o ServerAliveInterval=60' --host path-to-file/hostlist.txt

where hostlist.txt contains a list of user@YOUR_INSTANCE_PUBLIC_IPv4

Example of hostlist.txt

ubuntu@123.456.789.101
ubuntu@123.456.789.102
ubuntu@123.456.789.103 

One can obtain hostlist.txt from the following aws-cli command:

rm hostlist.txt 
for region in `aws ec2 describe-regions --query Regions[*].[RegionName] --output text`
do
     aws ec2 describe-instances --region $region  --filter "Name=instance-state-code,Values=16" --query Reservations[].Instances[].PublicIpAddress --output text >> hostlistraw.txt
done
tr '\t' '\n' < hostlistraw.txt > hostlist.txt
sed -i -e 's/^/ubuntu@/' hostlist.txt
rm hostlistraw.txt

References

[1] https://stackoverflow.com/a/10207871/2959347

[2] https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-key-pairs.html

Clone this wiki locally