Back to Blog

Recover lost access to OCI server - lost passwrod for RSA key

   Mariusz Antonik    Oracle Cloud (OCI)    3 min read    297 views

Idea to recover access to serve is to change RSA key 

Generate your public key

Login to OCI and create OCI consle 

Go to Instances/Server/Os Managment/Console Managment - click Create Local Connection

Past your RSA Key

Use menu on right "..." and select Copy Linux Connection - this will copy a command which you can use to estabilish connectioni with the server like 

ssh -o ProxyCommand='ssh -W %h:%p -p 443 ocid1.instanceconsoleconnection.oc1.us-sanjose-1.anzwuljr62zhyxacgiylaq6vyb7mw26wzrwnj3c5ft63fnzkxvjdvaz4jsma@instance-console.us-sanjose-1.oci.oraclecloud.com' ocid1.instance.oc1.us-sanjo-1.anzwuljr62zhyxxxxxxxxxxx

 

If you get error like 

=================================================
IMPORTANT: Use a console connection to troubleshoot a malfunctioning instance. For normal operations, you should connect to the instance using a Secure Shell (SSH) or Remote Desktop connection. For steps, see https://docs.cloud.oracle.com/iaas/Content/Compute/Tasks/accessinginstance.htm
 
For more information about troubleshooting your instance using a console connection, see the documentation: https://docs.cloud.oracle.com/en-us/iaas/Content/Compute/References/serialconsole.htm#four
=================================================
Unable to negotiate with UNKNOWN port 65535: no matching host key type found. Their offer: ssh-rsa

you need to update commad 

This is command which worked for me to get a console connection - you may little troubleshoot with AI for right command if ther is some missmatch in the version of the ssh (chatgtp give me this info after couple minutes of work)

ssh \
-o HostKeyAlgorithms=+ssh-rsa \
-o PubkeyAcceptedAlgorithms=+ssh-rsa \
-o "ProxyCommand=ssh -p 443 \
-o HostKeyAlgorithms=ecdsa-sha2-nistp256 \
-W %h:%p \
ocid1.instanceconsoleconnection.oc1.us-sanjose-1.anzwuljr62zhyxacgxxxxxxxxxxxxxxxxxxxxxxxx@instance-console.us-sanjose-1.oci.oraclecloud.com" \
ocid1.instance.oc1.us-sanjose-1.anzwuljr62zhyxac4z3zyxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx


 

 

We will try to login to server when it boot, and get access to single user mode.

After you setup the connection to console - restart server 

at startup press F12 to get list of kernels available. You need hit F12 in perfect moment, it took me several tries until I got this menu.

YOu may see this screen 

 

Then select Continue 

on next screen select kernel and press e

 

  • Next, select the Kernel version from the grub menu item and press e key to edit the first boot option. Now use the Down arrow key to find the kernel line (starts with “linuxefi“), then at the end of the line add the argument
    rw init=/sysroot/bin/sh
    as shown in the screen shot below

 

 

press Ctlr + x

 

 

after login execute 

chroot /sysroot/

now /home/opc folder is available and we can change ssh key 

cd /home/opc/.ssh

 

now you can edit this file 

vi authrized_keys

get your new public key and past to this file then reboot

 

 

At end of the file add empty line #end

once you done reboot server 

reboot -f

Change passwrod for root, or opc account 

passwd root

passwd opc

If you have some issies with server - check also selinux, check /var/log/messages and see if something is not correct. Sometimes SELINUX may block your access causing you a problem. Disable it, recover access to server and then enable it again 

 

 

 

 

 

 

 

Tags: #OCI
About the Author
Mariusz Antonik

Oracle Cloud Infrastructure expert and consultant specializing in database management and automation.

All Tags
#Advanced #Bash #bash cpu monitoring script #bash monitoring #bash scripting #Beginner #Best Practices #block volume backup #Capacity Planning #cloud backup strategy #cpu bottleneck #CPU Monitoring #cpu monitoring linux #cpu monitoring script linux #cpu trends #cpu usage trends linux #create oracle db system in oci #cron cpu monitoring #cron jobs #database monitoring #database performance #detect slow queries mysql #disk capacity planning server #disk forecasting linux #Disk Monitoring #disk usage #disk usage script linux #disk usage trends #Early Detection #easy infrastructure monitoring #free-tier #Guide #health dashboards #Health Reporting #historical server monitoring #infrastructure #infrastructure health #infrastructure health dashboard #infrastructure health reporting #infrastructure monitoring #infrastructure monitoring report #infrastructure trends monitoring #Infrastructure Visibility #lightweight linux monitoring #lightweight monitoring #linux administration #linux cpu monitoring #linux cpu usage #linux disk capacity planning #linux disk usage #Linux monitoring #linux monitoring tools #linux performance #linux performance monitoring #linux server #linux server monitoring #linux servers #linux storage #linux tools #low maintenance monitoring #monitor cpu usage over time linux #monitor linux server health #monitor server trends #monitor small production server #monitoring without complexity #MySQL #mysql health reporting #MySQL monitoring #mysql optimization #MySQL Performance #mysql performance degradation #mysql performance monitoring #mysql performance trends #mysql query performance issues #mysql server monitoring #mysql slow queries #mysql slow query analysis #mysql slow query monitoring #mysql trends #mysql-health #networking #nsg #OCI #oci backup #oci bastion tutorial #oci block volume #oci infrastructure as code #oci networking #oci oracle database private subnet setup #oci oracle database tutorial #oci security #oci setup guide #oci terraform tutorial #oci tutorial for beginners #oci vcn terraform #oci virtual machine db system guide #oracle base database service tutorial #oracle cloud bastion #oracle cloud free tier tutorial #oracle cloud infrastructure step by step #oracle cloud infrastructure tutorial #oracle cloud storage #oracle database on oci setup #oracle-cloud #Performance Degradation #performance monitoring #performance trend monitoring #performance trends #plan disk growth server #practical server monitoring #predict disk usage growth #private instance access #query optimization #Security #security lists #server health #server health reporting #server health weekly report #server monitoring #Server Performance #server trend analysis #server-trends #simple linux monitoring #simple monitoring system #simple ops monitoring #slow queries #slow query reporting mysql #small business infrastructure #small business IT #small business servers #small infrastructure monitoring #small server monitoring #ssh bastion #storage capacity planning linux #storage monitoring #subnets #system health reporting #terraform oci compute #terraform oracle cloud infrastructure #Trend Monitoring #Tutorial #vcn