-1

I have one running instance on aws and I lost my .pem file for that instance. So I go to network and security section of aws and created one new kaepair. After that I Run chmod 400 test.pem then I run ssh -i test.pem ec2-user@mypublicip

Then I got an option to enter password so I entered my aws password But my authentication got failed.

Please help me how I can login to my existing aws instance on new keypair

Akhilesh Jha
  • 168
  • 2
  • 11
  • I think this should help https://stackoverflow.com/questions/7881469/change-key-pair-for-ec2-instance – yadavankit Jun 15 '19 at 12:34
  • @yadavankit I don't want to Stop my instance – Akhilesh Jha Jun 15 '19 at 12:45
  • Creating a new keypair in AWS does not affect any currently running EC2 instances. If you have lost the keypair then you need to follow the steps in the question yadavankit linked. – Mark B Jun 15 '19 at 14:41

1 Answers1

1

The Connecting to Your Linux Instance if You Lose Your Private Key chapter in the EC2 user guide describes in depth how you can regain access to an EC2 instance. To summarize:

  1. Stop the instance (make sure to back up any data stored in the instance store to persistence storage that you would like to keep)
  2. Launch a temporary instance
  3. Detach the root volume of the original instance and attach it to the temporary instance
  4. Update the authorized_keys on the mounted volume with the new public key
  5. Unmount the volume from the temporary instance
  6. Attach the volume to the original volume
  7. Start the original instance
  8. (Terminate the temporary instance)

Please see the link above for details.

matsev
  • 32,104
  • 16
  • 121
  • 156