Simplifying SSH command to access Amazon EC2 server
If you are like me and you have to push the up arrow in your terminal window each time you need to remember exactly what the command is to access your Amazon EC2 server, here is a time saving SSH configuration trick for you.
example:
$ cd ~/.ec2 $ ssh -i davidskey.pem ubuntu@ec2-69-37-131-80.eu-west-1.compute.amazonaws.com
You can create a config file in your ~/.ssh directory to include your identity file for individual host names.
If your Amazon server has a public DNS entry which points to the long Amazon public DNS name, you can make this even easier.
$ cd ~/.ssh $ ls -al (if you don't find a file called "config" you can create one using the following line) $ touch config $ nano config
Add these lines: (assuming that dev.davidsdomain.com is a CNAME DNS entry which points to ec2-69-37-131-80.eu-west-1.compute.amazonaws.com.
Host dev.davidsdomain.com IdentityFile ~/.ec2/davidskey.pem
Host ec2-69-37-131-80.eu-west-1.compute.amazonaws.com IdentityFile ~/.ec2/davidskey.pem
Now you can SSH to both domain names using only the following. Also note that you do not have to change to the ~/.ec2/ directory to issue the SSH command anymore.
$ ssh ubuntu@dev.davidsdomain.com $ ssh ubuntu@ec2-69-37-131-80.eu-west-1.compute.amazonaws.com
One final note, is that this would work on any host that you use a keyfile to access via SSH. This is of course, not limited to Amazon EC2 server access.
[...] a previous post here, I showed you how to create a ~/.ssh/config [...]
Make it even easier. Create ~/bin/server
in there have:
#!/bin/bash
export sourceoptions=”TRUE server1 FALSE server2″
ans=$(zenity –list –text “Where do you want to be today?” –radiolist –column “Select” –column “Source” ${sourceoptions} –separator=”|”);
notify-send -t 1000 -u low -i gtk-dialog-info “Going places: ${ans} !”
ssh -X -C -i ~/.ssh/keys/$ans $1@$ans
and then you type server yourname … if your username is always the same replace $1 with it
The trick here: name your key file like the domain ($ans) and use zenity and notify-send for eye candy