1

I have to access a lot of AWS EC2 instances from my local machine regularly. Their IP addresses are not mapped to any domain to I need to login to them using command like :

ssh -i keyfile.pem ec2-user@<ip address of the instance>

There are over 10 EC2 instances and some have same key file some have different. The problem is that I do not remember their IP addresses and each time I have to look them up on my AWS console and then copy paste their IP address. Is there any way I can make this process a lot faster by storing some aliases to these instances locally and access them using some GUI tool ? I don't want to use PUTTY since I like the Ubuntu shell.

4
  • You can create alias alias MyInstanceID="ssh -i /path/to/Key/File ubuntu@Ip-address" Feb 18 '16 at 11:07
  • you can use my script to list your instance with their ip and tags at the command line shell ... http://linuxhomepage.com/free/list-aws.py
    – Skaperen
    Aug 27 '17 at 5:12
  • you can associate any ip with any name you like by appending to the file /etc/hosts. this is even more useful if/when you start using ipv6 with those long addresses.
    – Skaperen
    Aug 27 '17 at 5:15
  • you should have exactly one ssh key (referred to as id) per user. so for youself, just have one key pair. if you have multiple users, then who launches an instance should append the other public keys to .ssh/authorized_keys. a team can share them all as one file, concatenated ... each keeping their private halves to themselves.
    – Skaperen
    Aug 27 '17 at 5:31
1

You can try with shortcuts by specify the hostname, username, port, and the private key. Please refer the official docs.

Host MyInstance1
Host example.com or ipaddress
User ubuntu
IdentityFile /path/to/privatekey/MyInstance1.pem

Permission:

chmod 600 ~/.ssh/config

Then Try to access by

ssh  MyInstance1

You can also try with aliases :

File:

vi vim ~/.bash_aliases

Then

alias MyInstance1='ssh ubuntu@ec2.amazon.com -i /path/to/private-key/MyInstance1.pem'
1

An SSH config is great for this, however, upon redeploying new instances the IPs will change and your ssh config will become stale. I wrote a tool that will pull the latest EC2 inventory from AWS and ssh into the system that matches your search: https://github.com/wagoodman/bridgy

bridgy ssh <some-instance-id>

Or if you add a tag called Name to each instance then you can use that too:

bridgy ssh <some-name-tag-value>

If you have the ~/.aws creds/config defined as you would with the aws-cli as well as the following in ~/.bridgy/config.yml:

inventory:
    source: aws
    update_at_start: true
ssh:
    user: <your ssh user>
...

Then it should work!

One last thing: If you add all of your SSH keys to an ssh-agent then that will solve your problem regarding multiple key files (all keys are tried against the host you attempt to log into).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.