Wednesday, April 29, 2020

How To recover keys or connect to EC2(EBS) instance via user-data

In this post, let us see how to recover keys for EC2 instance(EBS) whose keys is lost 

  • AWS Account login and access
  • Permission or access to launch EC2

Getting Started :
  • Create an EC2 of your choice(I use Amazon Linux2 here); note that i dont have any role attached to this 

 The above instance is the key pair is lost
  • Create a new key pair from AWS EC2 Console

   Key pair will be created will look like this

  • Generate private key from this key pair; Connect to puttygen and open the acg-amz.pem file which is just generated and downloaded in local. Click on generate 'Public key' save it as 'acg-amz.ppk' to connect to putty connections

  • stop the instance now to amend the user data 

  • Select the instance, click on Action -> Instance settings -> View/Change user data. Copy the below data

  • Start the instance and connect using SSH and see the connection taken successfully, because the new public key has been copied via user data

  1. If the user data is not getting applied, then amend the [user-groups, once] tp [user-groups, always]
  2. Generate public key using puttygen or from ssh-keygen module from any other instance and use the same in user data
  3. IP Address might change when this process takes place

No comments:

Post a Comment