Last active
June 28, 2017 11:01
-
-
Save pacohope/a62b7b28bfc6a4fda4e950581540c665 to your computer and use it in GitHub Desktop.
Import a ssh keypair into EC2 in all AWS 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 | |
# I use an "Admin" profile that has all EC2 permissions | |
AWSPROFILE="Admin" | |
KEYNAME="my-aws-key" | |
KEYFILE="file:///Users/paco/.ssh/foo.pem" | |
# Create foo.pem via: | |
# sshkeygen -f /Users/paco/.ssh/foo.pub -e > /Users/paco/.ssh/foo.pem | |
# use ec2 describe-regions to get the official, up-to-the-minute region list. | |
REGIONS=$(aws ec2 describe-regions | jq -r '.Regions[].RegionName') | |
for i in $REGIONS | |
do | |
aws ec2 import-key-pair --profile "$AWSPROFILE" --region $i \ | |
--key-name $KEYNAME --public-key-material "$KEYFILE" | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment