-
Notifications
You must be signed in to change notification settings - Fork 1
How to run cluster ssh on MacOS
sorrachai edited this page Jan 23, 2018
·
7 revisions
To run identical commands on multiple EC2 instances simultaneously via ssh.
- 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:
- Upload local public-key to AWS EC2. Follow instruction from https://alestic.com/2010/10/ec2-ssh-keys/
- For existing instances, you can add your public-key: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-key-pairs.html
- For new instance, you can select existing key to be your local public-key before you launch.
- Install csshx, Cluster SSH tool for MacOS. Follow https://github.com/brockgr/csshx.
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
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
[1] https://stackoverflow.com/a/10207871/2959347
[2] https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-key-pairs.html