Posts Tagged: ElasticIP

Recovering a Lost Amazon EC2 SSH Key

amazon-ec2If you lose your Amazon EC2 SSH key and can’t log in to your instance, this isn’t a big problem as long as your instance is EBS-based and uses an Elastic IP.

1. Upload your new SSH key, or use one generated by AWS.

2. Create an AMI of your instance.

3. Launch a new instance from your AMI and select the new SSH key.

4. Log in to your instance with the default user (ubuntu or ec2-user, depending on your original AMI).

5. Reassign the Elastic IP to the new instance.

6. Turn off the old instance and terminate it.

Modern Alternatives (No Instance Replacement Required): Today you can usually regain access without cloning an AMI by connecting via AWS Systems Manager Session Manager, pushing a temporary key through EC2 Instance Connect, or stopping the instance to attach its root EBS volume to a temporary rescue VM and updating ~/.ssh/authorized_keys directly.