Skip to content

Instantly share code, notes, and snippets.

@gregtaylor99
Forked from pahud/aws-let-me-in.sh
Created March 23, 2018 01:34
Show Gist options
  • Save gregtaylor99/d15430cf61e351e0b51839df75cfb6c7 to your computer and use it in GitHub Desktop.
Save gregtaylor99/d15430cf61e351e0b51839df75cfb6c7 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