Import your own RSA SSH key into Amazon EC2

I read a few weeks ago that Amazon now allow you to import your own RSA keys into EC2, but at the time I couldn’t find anywhere that explained how to do it. However, I have now found out how thanks to an egyptian blogger.

It doesn’t look like it’s currently possible through the AWS management console, but you can do it through the command line tools. You have to upload your key to each availability zone separately, but thankfully this can be easily achieved with a one liner…

for r in us-east-1 us-west-1 ap-southeast-1 eu-west-1; do ec2-import-keypair --region $r paul-public-key --public-key-file ~/.ssh/id_rsa.pub ; done

Replace ~/.ssh/id_rsa.pub with the path to your public key, and paul-public-key with the name you would to appear in Amazon for your keys.

NB: You need the ec2 tools set up before you can run this. You will also need to have setup an x509 certificate pair. There’s some useful instructions for this here.

You can read more about the ec2-import-keypair command in the EC2 documentation.

One thought on “Import your own RSA SSH key into Amazon EC2”

  1. Amazon have added one region since you published this post, the new Tokyo region called ap-northeast-1. The command now becomes:
    for r in us-east-1 us-west-1 ap-northeast-1 ap-southeast-1 eu-west-1; do ec2-import-keypair –region $r my-public-key –public-key-file ~/.ssh/id_rsa.pub ; done

    (I called it my-public-key instead of paul as I uploaded the key called paul without noticing at first!)

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>