change keypairs ec2 running instance

前端 未结 3 1289
南方客
南方客 2021-02-04 12:51

Hello i\'ve made a big mistake with may key pairs on a ec2 Instance. I can\'t connect with sftp and putty because the private key is wrong.

How can i get access to my in

相关标签:
3条回答
  • 2021-02-04 13:12

    Steps:

    • Stop the instance
    • Create a new instance (which comes with a new volume and new key pair)
    • Detach your old volume from its instance and attach it to the new instance you just created along the new volume (so now you have two volumes attached to your new instance)
    • Start the new instance and mount the old volume (/dev/sdf is the default).
    • Copy contents of /home/ec2-user/.ssh and /etc/ssh from the new volume to the old volume
    • Stop the new instance and attach old volume to its main instance
    • Start your old instance

    Now you can use the new key pair you generated for the new instance, to connect to your old one.

    This did work for me and just a few notes:

    • Both instances were from same type and distribution
    • Instances shall be in the same Amazon region and zone
    • If you use elastic IP, re-attach elastic IP address as it will get released
    0 讨论(0)
  • 2021-02-04 13:14

    You can't change the keys on a running instance using the AWS console. Is this an EBS-boot volume, or using instance store? If the former, there is a roundabout way of doing it. If the latter, you're pretty much out of luck and will have to terminate the instance and create a new one.

    0 讨论(0)
  • 2021-02-04 13:23

    I think you need to rebuild the instance with a old(correct) key pair.

    http://docs.amazonwebservices.com/AWSSecurityCredentials/1.0/AboutAWSCredentials.html#EC2KeyPairs

    0 讨论(0)
提交回复
热议问题