Security – AWS EC2 SSH from the IP address which has changed


I often discover that my IP address (Google what is my IP) has changed thus SSH into my EC2 fails since it accepts SSH from my IP address.

What are my options?

1) Ask my ISP for a static IP address?
2) Open EC2 to accept SSH from – relay on the private key.pem file only?
3) Keep changing my IP address in the AWS security group as well the other hosting company for my MongoDB.

Any other suggestions?

Best Answer

Go with #3. It's trivial to write a small script you can run that will:

  1. Fetch your current public IP
  2. Use that IP and awscli to update your security group

Stick this script on your desktop and you're two clicks away from updating your SG. Or even better, run it via cron on the hour.