Posted by : Debashis Wednesday, September 25, 2013


This tutorial will show you how to use a new Key Pair with an existing Ubuntu EC2 instance.

Problem:


You have an existing EBS (root device) based Instance with data on it that needs to be saved. The original Key Pair has been lost so you can’t log into the Linux Instance. You need to get to the data on the virtual machine. Or else by some reason you want to change the existing key pair with a new key pair.

Solution:
I’ll clone the running Instance and re-deploy it but with a new Key Pair. We can either use a pre-made Pair or create a Pair while we’re re-deploying. My example uses Ubuntu but should apply to other flavors as well.

Creating an Image:
Log into your Amazon Web Services (AWS) Management Console, go to Amazon EC2, pick the Region where the Instance in question is running and click on the Instances link. Right click on the Instance in question and select “Create Image (EBS AMI)” from the resulting menu.





Give it a Image Name and a Description and click on “Yes Create” button. Example:



The process will now begin.  Close the notification window.

Once the AMI is created (won’t take long) you should see it in the "Images" - "AMIs" part of your Amazon EC2 AWS Management Console. Please make sure you are still in the correct Region. Example:




Creating new Instance out of the new AMI:

Go to Images AMIs, locate your recently created AMI, right-click on it and select “Launch Instance” from the resulting menu.




While lunching new instance create & download the new key pair


After launching the instance you can see both the instances with same content and different keys.


You can now connect to it, using your new private key, and confirm that all your data is still there.
Once you confirm no data is missing you can stop the old Instance and eventuality terminate it (after making absolutely sure you will never need anything from it.
Cleaning Up:

You can now de-register the AMI (unless you want to use later again).


You should also go to EBS - Snapshots and delete the Snapshot of the disk that was created when the AMI was made (unless you intend to use it for something in the future).





You can download the pdf version from HERE



Leave a Reply

Thank you for your valuable feedback !

Subscribe to Posts | Subscribe to Comments

- Copyright © Smart Deb