SSH into EC2 instances via tag name
Switch branches/tags
Nothing to show
Clone or download
Pull request Compare This branch is 46 commits ahead of facebookarchive:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.



A pair of command line utilities for finding and SSH-ing into your Amazon EC2 instances by tag (such as 'Name').

Forked from Instagram original code by YPlan.


From pip:

pip install ec2-ssh

Python 2 and 3 compatible.


There are two utilities: ec2-ssh and ec2-host.

1. ec2-ssh

Use the ec2-ssh command to SSH into your instances. Rather than a hostname to SSH into, it takes a tag key (default Name) and value, looks up the instances matching that tag, randomly picks one (if there is >1) and uses its public hostname, or private IP if it's not public. The username is defaulted to ubuntu.

For example:

$ ec2-ssh myapp
# looks up instances where Name=myapp, expands out to something like:
# ssh

$ ec2-ssh root@myapp
# expands to
# ssh

You can pass the -t / --tag option to use a different tag key to search on, for example:

$ ec2-ssh -t role myapp-frontend

All other options are passed through to SSH so you can do things like:

$ ec2-ssh myapp -- sudo systemctl restart nginx
$ ec2-ssh -vvv myapp  # why can't I connect??

2. ec2-host

This tool exposes just the host-lookup logic from ec2-ssh you can use it for other purposes. The only difference is that rather than returning just one matching instance's hostname/IP, it will return all of them. For example:

$ ec2-host  # no tag, prints all instance hosts

% ec2-host myapp  # only instances where Name=myapp

% ec2-host -t environment prod  # instances where environment=prod