How to connect to OCI machine if the sshd is not responding?

2.8k views Asked by At

I was updating the ssh port of an Oracle Cloud Infrastructure machine

I changed /etc/ssh/sshd_config The port was

#Port 22

I changed it to

Port 40531

Then

  1. restarted the sshd service systemctl restart sshd
  2. open the port on the OCI Web

however, now I cannot connect.

ssh -vvv -p 40531 -i ~/.ssh/vm.key [email protected]
OpenSSH_8.2p1, OpenSSL 1.1.1e  17 Mar 2020
debug1: Reading configuration data /etc/ssh/ssh_config
debug2: resolve_canonicalize: hostname 129.xxx.xxx.xxx is address
debug2: ssh_connect_direct
debug1: Connecting to 129.xxx.xxx.xxx [129.xxx.xxx.xxx] port 40531.
debug1: connect to address 129.xxx.xxx.xxx port 40531: Connection timed out
ssh: connect to host 129.xxx.xxx.xxx port 40531: Connection timed out

I saw a Cloud Shell but I'm not sure if it can be used to connect to the machine to perform maintenance tasks

Is there a way to connect to the VM from the web oci interface to fix the ssh issues?

I used to use a VPS service that has a web console from which you can enter to fix problems like this

is there something like this in OCI?

Note:

  • SELinux was disabled on the machine
  • if you are about to do this on your machine, remember to update the SELinux configuration prior restart the sshd service or you will be locked out, another option is to disable SELinux totally (this is what I did)
2

There are 2 answers

1
Frederick Álvarez On BEST ANSWER

The changes above described worked well, the only thing that was causing issues on my side (I don't really know why) is that I was connected from a VPN

After I disconnected the VPN and tried to connected again it worked

Update:

I figured out why the ssh using a different port was not working. The VPN I use is a corporate VPN which has very strict inbound and outbound rules, The VPN outbound rules were blocked by the TCP on port 40xxx.

Update:

if you are struggling with a VM you can connect using the below instruction

Creating the Instance Console Connection Before you can connect to the serial console or VNC console, you need to create the instance console connection.

To create the console connection for an instance
Open the navigation menu. Under Core Infrastructure, go to Compute and click Instances.
Click the instance that you're interested in.
Under Resources, click Console Connection.

Click Create Console Connection.
Upload the public key (.pub) portion for the SSH key. You can browse to a public key file on your computer or paste your public key into the text box.
Click Create Console Connection.

When the console connection has been created and is available, the state changes to Active.

enter image description here

Thanks to @bmuthuv for the info

1
bmuthuv On

You can connect to Serial Console of the VM where you could get access to GRUB Menu during a Reboot operation. You can subsequently use typical Linux commands to get to Shell from Grub. You can subsequently undo anything you would like to.

Serial Console connection can be created on OCI Web Console in the Instance's page.