How to access an EC2 instance after losing the Key Pair?

2

I lost my Access Key Pair to an EC2 server, how do I retrieve it?

Is there a way to generate a new Key Pair and add it to an existing instance?

    
asked by anonymous 18.03.2014 / 06:08

3 answers

4

If the user loses the Key Pair, and has not previously prepared any other form of access to your instance, there is really nothing to do - Access is lost ! (except in special cases, see below)

This is because AWS has no way to access your instance - you were the only one who had the key. The key is installed on the instance itself during the first boot process - AWS has no way to connect to your instance and change the key for you. In subsequent boots, this process does not run, so it's no use generating a new key from the console, with a new name or even a name, or anything like that.

Depending on your specific circumstances, you can do a very manual and laborious process to gain access back to your instance. This process only applies to instances that use EBS as the root device, and in addition all content written to instance store will be lost.

From the AWS documentation:

  

Amazon EC2 does not keep a copy of your private key; therefore, if you lose your private key, there is no way to recover it. If you lose the private key for an instance store-backed instance, you can not access the instance; you should terminate the instance and launch another instance using a new key pair. If you lose the private key for an EBS-backed instance, you can regain access to your instance.

Source and more information about the recovery process: link

    
03.04.2014 / 22:37
2

Another way to solve this would be:

  • Stop the instance with the lost Key Pair (Use the Stop , not Terminate , huh?)
  • Create a new instance with same OS and instance region without Key Pair
  • Generate a new Key Pair
  • Stop the instance you just created
  • Disconnect the default EBS disk from the new instance
  • Connect the old machine's disk to the new instance. Make sure it is as /dev/sda1
  • Reseat the new instance.
  • You have the option of either using Volume EBS that was created together with the new instance or reconnecting it to the instance as an extra disk, which could serve as backup for example.

        
    28.10.2014 / 23:38
    0

    We have 2 possibilities:

    • Locally generate the key pair with the ssh-keygen command (for Unix-derived systems) and import the public key with the Import Key Pair button.
    • >
    • Generate a new key pair using the Create Key Pair button. Then soon Amazon sends the private key for you to save.

    All this is in the EC2 Console , Network & Security > Key Pairs .

        
    18.03.2014 / 07:02