Using SSH Host shortnames to connect to Amazon EC2 servers

On December 9, 2011, in AWS, Mac, by Anuj Gakhar

I work with quite a few different Amazon EC2 instances on a daily basis and I use SSH command line interface to connect to these servers and as you can imagine, a normal command for that would look something like this :-

ssh -i ~/.ec2/server.pem

Now, imagine typing that in for 5 different servers multiple times during the course of your day. Well, I have been doing that for a long time, until today, that is. Apparently, you can define the commonly used SSH hosts in the SSH config file.

First of all, create the SSH config file if you don’t have it already :-

sudo vim ~/.ssh/config

Then, enter your commonly used hosts in that file :-

Host server1
User ubuntu
IdentityFile ~/.ec2/server1.pem

Host server2
User root
IdentityFile ~/.ec2/server2.pem

Host server3
User ubuntu
IdentityFile ~/.ec2/server3.pem

You can add as many hosts as you want…and once you are done, you can SSH into these servers like this :-

ssh server1
ssh server2
ssh server3

Isn’t that cool? I can see that saving me quite a lot of typing everyday.

Tagged with:  

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 446 other subscribers

© 2011 Anuj Gakhar
%d bloggers like this: