Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to connect to Linux when an AWS key pair is lost

Shulou Source: shulou.com Published: 2022-06-01 06:33:29 10月05日 Update

AWS key pair lost how to connect to Linux, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.

If you lose the private key of an instance supported by EBS, you can regain access to your instance. You must stop the instance, disconnect the root volume and connect it to another instance as a data volume, then modify the authorized_keys file, move the volume back to the original instance, and restart the instance. If the root device is an instance storage volume, you must have a private key to connect to the instance.

Stop (stop) the original instance to connect to

Note: write down the partition number of the instance storage device of the original instance, such as / dev/xvda.

Unmount the large root volume of the original instance and mount it to the temporary instance (the new temporary linux instance)

Connect to a temporary instance.

"in a temporary instance, install the volume connected to the instance to access its file system." "for example, if the device name is / dev/sdf, install the volume as / mnt/tempvol using the following command."

A use the lsblk command to determine if the volume is partitioned.

b. Create a temporary directory to install the volume.

[ec2-user ~] $sudo mkdir / mnt/tempvol

c. Install the volume (or partition) at the temporary mount point using the volume name or device name determined earlier.

[ec2-user ~] $sudo mount / dev/xvdf1 / mnt/tempvol

On a temporary instance, update the authorized_keys on the installed volume to a new public key from the temporary instance authorized_keys using the following command (you may need to swap in a different user name, such as ubuntuubuntu for the instance) in the following command:

[ec2-user ~] $cp .ssh / authorized_keys / mnt/tempvol/home/ec2-user/.ssh/authorized_keys

If the replication is successful, you can go to the next step.

In a temporary instance, unmount the connected volume to reconnect it to the original instance. For example, unmount the volume at / mnt/tempvol using the following command:

[ec2-user ~] $sudo umount / mnt/tempvol

Unmount the volume from the temporary instance and mount it back to the original instance.

Log in to the original instance for verification.

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Tags: Instance command key device original name file storage help support private different clear success content storage device this data article novice Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple MySQL NVidia macOS Linux