change keypairs ec2 running instance

前端 未结 3 1287
南方客
南方客 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

提交回复
热议问题