What should you do if you lost your AWS SSH keys or Not able to do SSH in your EC2 Machine?

Manish Soni
Edu-Adda
Published in
Oct 31, 2020
Photo by Emily Morter on Unsplash

Have you wondered if you lost your ssh keys or not able to do ssh in your production ec2 machine?

This will really become big problem if you don’t know how to troubleshoot such problems.

you can do following things if your instance is EBS Backed:-

  1. Stop the instance and detach the root volume
  2. Attach the root volume to another instance as a data volume.
  3. Modify the ~/.ssh/authorized_keys file with your new key
  4. Move the volume back to the stopped instance
  5. Start the instance and you can SSH into it again

But we can use these methods only when we get problems in Dev or Test Environments, we can’t perform these steps in production and instance store backed volumes because of downtime or data loss.

Use AWS SSM(System Manager) in that case.

Run the AWSSupport-ResetAccess automation document in SSM.

find more here https://docs.aws.amazon.com/systems-manager/latest/userguide/automation-awssupport-resetaccess.html if you want to know more about this automation.

Use AWS Session Manager to access your instance and edit ~/.ssh/authorized_keys file directly in Instance store backed volume.

Happy Reading!!

--

--

Manish Soni
Edu-Adda

DevOps Engineer, AWS Certified Solutions Architect Reach me out at → https://mani1soni.github.io/