Skip to content

Instantly share code, notes, and snippets.

@loa
Last active August 29, 2015 14:10
Show Gist options
  • Select an option

  • Save loa/e72e88797076e77c31dd to your computer and use it in GitHub Desktop.

Select an option

Save loa/e72e88797076e77c31dd to your computer and use it in GitHub Desktop.
AWS EC2 upload ssh pub to all regions
#!/bin/bash
# http://alestic.com/2010/10/ec2-ssh-keys
which aws > /dev/null 2>&1 || {
echo "ERROR: missing aws-cli"
echo "http://aws.amazon.com/cli/"
echo "$ brew install awscli"
exit 1
}
which jq > /dev/null 2>&1 || {
echo "ERROR: missing jq"
echo "http://stedolan.github.io/jq/"
echo "$ brew install jq"
exit 1
}
keyname="${USER}"
publickeyfile="file://${HOME}/.ssh/id_rsa.pub"
regions=$(aws ec2 describe-regions | jq '.Regions[].RegionName' -r)
for region in ${regions}; do
echo ${region}
aws ec2 import-key-pair \
--region ${region} \
--key-name ${keyname} \
--public-key-material ${publickeyfile}
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment