Run the AWSSupport-ResetAccess
automation document via AWS Systems Manager.
Detailed doc here
- Stop (don't terminate it) the instance and detach the root volume
- Access a second instance (that you have its pem) and attach the root volume as a data volume
- Modify the
~/.ssh/authorized_keys
file with you new key - Reattach the volume back to the stopped instance
- Start the instance and connect via ssh to it
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.