Remove default SSH host keys before publishing an AMI

AMIs that have the same ssh host key pairs as other public amis will be made private by amazon to prevent man-in-the-middle attacks, so always remove SSH Host Key Pairs (they will be regenerated with new unique keys automatically)

rm /etc/ssh/ssh_host_dsa_key
rm /etc/ssh/
rm /etc/ssh/ssh_host_key
rm /etc/ssh/
rm /etc/ssh/ssh_host_rsa_key
rm /etc/ssh/

Creating a EC2 Micro instance via Fog

0.03c/hour (14€/month) is pretty cheap for a small server so lets try this 🙂

Generate and download a key-pair, so you can login to the instance via ssh.

AMI-id used is a micro ebs ubuntu 10.04 instance on eu-west-1, choose your own at

Be sure to add ssh port to your security group or you will get a nice “port 22: Connection timed out”

Start the servers!

require 'fog'
fog =
  :provider => 'AWS',
  :aws_access_key_id => 'yyy',
  :aws_secret_access_key => 'xxxx'

# start a server
server = fog.servers.create(
  :key_name => 'pey-pair-name'

# wait for it to get online
server.wait_for { print "."; ready? }

# public address -> -> ssh into it

# instance id -> find it again

# shutdown

Connect via ssh

ssh -i KEY-PAIR.pem ubuntu@SERVER-DNS-NAME