Skip to content

Instantly share code, notes, and snippets.

@rodrigo-galba
Last active March 23, 2020 17:47
Show Gist options
  • Save rodrigo-galba/ba71508b982a8aeaee79beafe4bf1c13 to your computer and use it in GitHub Desktop.
Save rodrigo-galba/ba71508b982a8aeaee79beafe4bf1c13 to your computer and use it in GitHub Desktop.
AWS EC2 recovery credentials

What if I lost my EC2 ssh key?

For EBS backed instances

1 - Best option

Run the AWSSupport-ResetAccess automation document via AWS Systems Manager.
Detailed doc here

2 - Modify ssh authorized keys

  1. Stop (don't terminate it) the instance and detach the root volume
  2. Access a second instance (that you have its pem) and attach the root volume as a data volume
  3. Modify the ~/.ssh/authorized_keys file with you new key
  4. Reattach the volume back to the stopped instance
  5. Start the instance and connect via ssh to it

For Instance Store backed EC2 instances:

It is not possible to stop the instance (otherwise data will be lost)

Use AWS Session Manager access and edit the ~/.ssh/authorized_keys file directly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment