Skip to content

Instantly share code, notes, and snippets.

@benhutchins
Last active September 30, 2016 05:47
Show Gist options
  • Save benhutchins/f9d94db65069851af937440f8cba432c to your computer and use it in GitHub Desktop.
Save benhutchins/f9d94db65069851af937440f8cba432c to your computer and use it in GitHub Desktop.
Simple script to quickly add yourself to a security group, ssh in, then disconnect when you are done
HOST=$1
if [ -z $HOST ]; then
echo "You did not provide a host"
else
IP=`curl -s echoip.com`
# set the AWS Security Group based on host
if [ $HOST = "staging" ]; then
AWS_SG_ID=sg-12345
fi
# update security group
aws ec2 authorize-security-group-ingress --group-id $AWS_SG_ID --protocol tcp --port 22 --cidr $IP/32
echo "Added your IP $IP to security group $AWS_SG_ID"
# now connect to host
ssh $HOST
# cleanup security group
aws ec2 authorize-security-group-egress --group-id $AWS_SG_ID --protocol tcp --port 22 --cidr $IP/32
echo "Cleanup up security group"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment