Skip to content

Instantly share code, notes, and snippets.

@frederico
Created February 7, 2011 19:34
Show Gist options
  • Save frederico/815021 to your computer and use it in GitHub Desktop.
Save frederico/815021 to your computer and use it in GitHub Desktop.
SSH access AWS EC2 - Script Authorized keys for EC2
#bin/sh
# Script to authorize EC2 instance
# You can use id_rsa or id_dsa, i'm using id_rsa then:
# PEM_FILE must be seted
KEY="$HOME/.ssh/id_rsa.pub"
PEM_FILE=""
if [ ! -f $KEY ];then
echo "private key not found at $KEY"
echo "* please create it with \"ssh-keygen -t rsa\" *"
exit
fi
if [ -z $1 ];then
echo "Usage: $0 username@host"
exit
fi
if [ "$PEM_FILE" == "" ];then
echo "PEM_FILE must be seted, please open script and set env PEM_FILE"
exit
if [ -f $PEM_FILE ];then
echo 'File do not exist please set env PEM_FILE correctly'
exit
fi
fi
echo "Putting your key on $1... "
ssh -i $PEM_FILE -q $* "umask 0077; mkdir -p ~/.ssh ; echo \"`cat $KEY`\" >> ~/.ssh/authorized_keys"
echo "done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment