Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SSH to Amazon EC2 using instance ID only

I would like to turn on/off some of my Amazon EC2 instance, but this causes the IP and all DNS names to change. Therefore when I boot my machine again, all my SSH configurations are lost since I was connecting using the previous DNS name.

Is there a simple way to resolve the dns of the target machine (with no or as low as possible cost) using only its instance-id (or any other parameter that do not change over shutdowns-restarts) ? Do I have to use the AWS-CLI ? What if I want to provide an access to an EC2 machine to someone who doesn't have AWS credentials ?

Not sure if tags like "service-discovery", "broker", or "proxy" would really make sense here, but for the sake of references I'm adding them in my post.

I do not want to pay for elastic IPs.

like image 620
Cyril Duchon-Doris Avatar asked Nov 04 '25 05:11

Cyril Duchon-Doris


1 Answers

There are already Utils that do this, no need to roll your own: ec2ssh is a python script to do it but a google for ec2ssh will turn up numerous similar tools in multiple languages that will do the job.

Personally, I setup a bastion with an EIP, and jump from there to all the other hosts. This way you don't need to give your Instances public IPs just for admin access. If your not transferring large files you can get away with a t2.nano as the bastion instance, which with a reservation costs you peanuts a month.

Ec2ssh has bastion support so the config overhead is minimal.

like image 105
Nath Avatar answered Nov 07 '25 04:11

Nath



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!