We spin up and down a lot of EC2 instances at my job, and I wanted to share my SSH Config that makes life easier:
$ cat ~/.ssh/config Host *amazonaws.com IdentityFile ~/.ssh/organization.pem User ec2-user StrictHostKeyChecking no UserKnownHostsFile /dev/null
Here’s what it does:
- IdentityFile: Makes it so I don’t have to use the
-iswitch every time. The identity file is from the EC2 security group we use, so it’s always the same. - User: The AMI we use always has the user “ec2-user”
- StrictHostKeyChecking: By setting this to “no”, you won’t get warnings about how the ip address has changed. This is an issue with EC2 since they re-use ips, and we use scripts to bring up and down machines, so we can’t have the scripts expecting any input
- UserKnownHostsFile: This actually prevents the previous bullet point from happening. This says don’t every try to remember the host
So what is the result of this? Well, given an EC2 instance I just spun up, all I do to log in is:
$ ssh ec2-54-245-6-48.us-west-2.compute.amazonaws.com
Much easier!