Created
October 27, 2015 16:08
-
-
Save pjbull/a45e5ce43ffe4d096124 to your computer and use it in GitHub Desktop.
SSH to Running EC2 Ubuntu Instance
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# I keep this in my .bashrc to get to a running EC2 instance if there is only one running with my current creds | |
export AWS_EC2_PEM=<PATH_TO_PEM> | |
function ec2me () { | |
running=$(ec2-describe-instances | grep running) | |
instances=$(wc -l <<< "$running") | |
if [ $instances = 1 ]; then | |
server=$(cut -f4 <<< "$running" ) | |
echo "Connecting to $server" | |
ssh -i $AWS_EC2_PEM ubuntu@$server | |
else | |
echo "ERROR: CAN'T CHOSE SERVER: There are $instances instances running:" | |
echo "$running" | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment