Skip to content

Instantly share code, notes, and snippets.

@duggan
Last active December 23, 2015 23:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save duggan/6712237 to your computer and use it in GitHub Desktop.
Save duggan/6712237 to your computer and use it in GitHub Desktop.
Import public key to all EC2 regions. Required ec2-tools. Dedicated to @whiteley
#!/bin/sh
#
# Imports a public key to all EC2 regions.
#
# Usage:
# sh import-keypair <name> <path>
#
# Example:
# sh import-keypair foo ~/.ssh/foo.pub
#
if [ "x$1x" = "xx" ] ; then
printf "You must specify the keypair name\n"
exit 1
fi
if [ "x$2x" = "xx" ] ; then
printf "You must specify the path to your public key\n"
exit 1
fi
name=$1
location=$2
regions=$(ec2-describe-regions | cut -f2 | xargs)
for region in $regions ; do
ec2-import-keypair --region=$region -f $location $name
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment