Sunday, April 26, 2020

HowTo recover lost Keypair of AWS EC2(EBS) instance manually




If an AWS EC2 instance is launched and for some reasons the key-pair is lost. What is the next step?? Let us see how to restore the lost key pair in this blog post



Pre-requisites:
  • AWS login access
  • Permissions to create EC2

Getting Started:
  • Login to the AWS EC2 Console Page
  • Stop the EC2 instance for which the key pair is lost; below is the EC2 for which the Keypair is lost now and hence stopped to detach volume based on InstanceID



  • Gather the EC2 instance ID, go to Volumes Page, locate the instances' volume and detach the volume



  • Attach the volume to the newly created EC2-with-kp instance;below is the instance for which keypair is available


  • Mount this new volume in EC2-with-kp instance


  • SSH to new EC2 to copy new key pair to the volume just attached; to update the ~/.ssh/authorized_keys in the mounted volume(from EC2-wo-kp)


  • Detach the volume from EC2-with-KP
 
  • Attach the unmounted volume(with the keys copied) against EC2-wo-kp and start the EC2 instance



  • Now we can ssh to this EC2 instance using new key pair



                                                       Happy Recovery !!

No comments:

Post a Comment