Today, I tried to connect to my server on the Oracle Cloud Infrastructure instance, but either I lost my private key or, for some unknown reason, your opc user SSH key got corrupted or deleted. It might be scary at first, but the process of recovering an opc user SSH key on Oracle Cloud Infrastructure is easier than you think.
- Stop the instance that you can’t log in to.
Stop the instance that you can’t connect to. In the Oracle Cloud Infrastructure Console, go to the details page for the instance and click Stop.
2. Detach the boot volume.
Detach the boot volume. In the Boot Volume section, click the Actions icon and choose Detach.
3. Attach the boot volume to a running Linux instance.
Attach the boot volume to another Linux instance by going to Block Storage >> Boot Volumes >> Boot Volumes Details. Click Attach to Instance in Attached Instances.
Select the iSCSI, Select Instance and click in Attach
Run the iSCSI commands to attach the device and make it visible to the local operating system.
Your boot-volume should appear as /dev/sdb3.
4. Fix the authorized_keys file.
Make /dev/sdb3, which is the root (/) partition where you can recover the opc SSH key file, available to the local operating system using “mount” command.
sudo mount /dev/sdb3 /mnt
5. Fix the opc SSH key by editing the /mnt/home/opc/.ssh/authorized_keys file and adding your SSH key public file.
sudo vi /mnt/home/opc/.ssh/authorized_keys
After you add or change the SSH public key you need to use, save, and exit it.
6. Run umount /mnt.
sudo umount /mnt
7. Detach the iSCSI boot volume by running the detach iSCSI commands.
Unmount the device and detach it by running the iSCSI commands
Ensure that the /dev/sdb disk is no longer available or visible through the SSH connection, and then detach it.
Click in Continue Detachment
Click in Detach
8. Reattach the boot volume to the instance where you wanted to recover the SSH key, wait for it to become operational.
Click in Attach Boot Volume
After the boot volume is attached, start the Compute Instance.
See you soon in other articles.
Stay tuned by following us on Twitter @aontalba and Linkedin.
Disclaimer: “The postings on this site are my own and do not necessarily represent my current employer positions, strategies, or opinions. The information here was edited to be useful for general purpose, specific data, and identifications was removed to allow reaching a generic audience and to be useful.”