Connecting to EC2 servers from Mac using shortnames

If you have to connect to a number of EC2 machines, typing a long command that looks like the following each time can be painful.

ssh -i  /somepath/somefile.pem   someuser@someserver.compute-1.amazonaws.com

A way to make this command much shorter is by using SSH config file.

Edit (or create) file ~/.ssh/config

vi ~/.ssh/config

Now for each EC2 server that you connect to, add a section that looks like this…

Host test1
HostName 100.100.100.100
User ec2-user
IdentityFile /User/name/ec2pems/test1.pem

Now you can connect to the instance by typing a command that looks like this…

ssh test1

Leave a comment