Last active
August 29, 2015 14:10
-
-
Save loa/e72e88797076e77c31dd to your computer and use it in GitHub Desktop.
AWS EC2 upload ssh pub to all regions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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