Skip to content

Instantly share code, notes, and snippets.

@blalor
Created March 13, 2014 13:35
Show Gist options
  • Select an option

  • Save blalor/9528597 to your computer and use it in GitHub Desktop.

Select an option

Save blalor/9528597 to your computer and use it in GitHub Desktop.
ssh to ec2 instances by Name tag

Log into EC2 instances naturally without having to figure out their public hostname ahead of time!

$ ssh [email protected]
Last login: Wed Mar 12 22:06:27 2014
[ec2-user@ip-10-158-37-24 ~]$ 
#!/bin/bash
set -e -u
instance_name="$1"
port="$2"
hostname="$( aws ec2 describe-instances --filters Name=tag:Name,Values=${instance_name%.ec2} | jq -r .Reservations[].Instances[0].PublicDnsName )"
exec nc ${hostname} ${port}
Host *.ec2
ProxyCommand ~/bin/ssh-ec2.sh %h %p
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment