Skip to content

Instantly share code, notes, and snippets.

@pahud
Created June 30, 2016 12:29
Show Gist options
  • Save pahud/1d1a8768d393fc798ec0024fcba59e31 to your computer and use it in GitHub Desktop.
Save pahud/1d1a8768d393fc798ec0024fcba59e31 to your computer and use it in GitHub Desktop.
aws-let-me-in
#!/bin/bash
myip=$(curl -s https://myip.today)
sg='sg-XXXXXXXX'
ssh_port='4123'
aws_ec2_cmd='aws --profile myprofile ec2'
open_door(){
echo "=> opening the door for $myip"
myip=$1
$aws_ec2_cmd authorize-security-group-ingress --port $ssh_port --cidr $myip/32 \
--protocol tcp --group-id $sg && \
echo "=> door opened"
}
close_door(){
echo "=> closing the door for $myip"
myip=$1
$aws_ec2_cmd revoke-security-group-ingress --port $ssh_port --cidr $myip/32 \
--protocol tcp --group-id $sg && \
echo "=> door closed"
}
ssh_cmd() {
ssh base
}
open_door $myip && ssh_cmd;
close_door $myip
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment