If this is your first time creating an instance, we recommend creating a Virtual Cloud Network (VCN) first. You can use the "Start VCN Wizard" workflow and select the "Create VCN with Internet Connectivity" option. The workflow creates a VCN which automatically configures both a public and a private subnet along with any required gateways and route rules. In addition, the workflow provides an option to configure IPv6. For details on running the workflow see: Virtual Networking Quickstart.
SSH Error: connect to host w.x.y.z port 22: Operation timed out
The error means SSH can't connect to the host at the IP address specified. Check the following scenarios to resolve the issue.
Ensure the System has Internet Access 🔗
Ensure the Environment the SSH command is executing and has Internet Access
Windows: Open a command prompt window.
MacOS/Linux: Open a terminal window.
Ping a well known host like google.com or amazon.com.
If the ping command is successful, continue to the next option.
Ping Failed
Your SSH environment might not have access to the internet. If you unsure about your organizations firewall settings for internet access, consider using OCI
Cloud Shell to SSH to the instance. See the OCI
Cloud Shell Section on this page for details.
Proxy Servers
If your organization uses proxy servers to connect to the internet, make sure your proxy settings are correct. Please consult your organizations proxy documentation as the settings can vary depending upon the proxy configuration and the operating system used.
Check the OCI Settings 🔗
Next, check the OCI settings to verify your configuration.
After setting the IP address, restart the instance and try using SSH to connect to your instance.
The Instance has a Public IP Address on a Public Subnet and I still Can't Connect 🔗
If you are new to OCI, the following troubleshooting steps are more advanced. To speed things up, consider setting up a new VCN and a new Compute instance as described in the following tips.
Tip
If this is your first time creating an instance, for a guided tutorial consider one the following:
If this is your first time creating an instance, we recommend creating a Virtual Cloud Network (VCN) first. You can use the "Start VCN Wizard" workflow and select the "Create VCN with Internet Connectivity" option. The workflow creates a VCN which automatically configures both a public and a private subnet along with any required gateways and route rules. In addition, the workflow provides an option to configure IPv6. For details on running the workflow see: Virtual Networking Quickstart.
Open the navigation menu and select Compute. Under Compute, select Instances.
Select the instance you are interested in. The instance details page is displayed.
Review the VCN Configuration
Click the VCN assigned to this instance.
Ensure at least one Internet Gateway is available in the Internet Gateways resource.
If no Internet Gateway is assigned, go to the next section.
If an Internet Gateway is assigned, ensure your public subnet has a route rule assigned for the gateway.
Under the Subnets resource, select your public subnet.
Under Subnet Information click the Route table link.
Ensure there is a static route with a destination of 0.0.0.0/0.
If the route entry is missing, go to the next section.
My Public Subnet isn't Properly Configured
If it appears your public subnet isn't configured properly, you have two options to reconfigure your subnet.
(1) Use the Compute Quick Action.
From the instance details page:
In the Resources list, select Quick Actions.
Click Connect on the Connect public subnet to internet quick action.
Follow the workflow to connect your instance.
(2) Manually create a public subnet.
Use the Scenario A: A Public Subnet document to walk through the steps to setup and configure a new public subnet.
Create a new Compute instance in the new public subnet.
Check Security Lists
If you're continuing to have issues, ensure your security lists allow traffic on port 22. See Security Lists for details.
Advanced Troubleshooting
If you're an advanced user, you can use the Network Path Analyzer to further troubleshoot the network connection. See Network Path Analyzer for details.
SSH: Connect to host w.x.y.z port 22: Connection refused 🔗
This error message is caused because a host is listening at the target address, but you can't connect to port 22.
Use Netcat(nc) to verify that SSH is Running 🔗
Linux or MacOS
In a terminal window, run the following command:
Copy
nc <public ip> 22
If the command returns a message similar to:SSH-2.0-OpenSSH_9.4
You successfully connected to the instance and verified SSH is running. Double check the IP address in your SSH command, ensure it is correct.
If the command returns nothing:
Check the public IP address on the instance detail page to ensure you are using the correct address.
Double check the IP address used in the command, ensure it is correct.
Otherwise, continue to the next section.
Windows
In a PowerShell window, run the following command:
This occurs because Linux instances supports OpenSSH generated SSH keys and PuTTYgen generated SSH keys use a different format.
Make SSH Key Formats Match
If you're using .ppk keys generated with PuTTYgen to log into a Linux instance using the OpenSSH SSH command, the connection fails. For example:
$ ssh -i deployment_key.txt opc@<IP_ADDRESS>
Enter passphrase for key 'deployment_key.txt':
Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
This error occurs because Linux instances support OpenSSH generated SSH keys and PuTTYgen generated SSH keys use a different format. To resolve this issue, use PuTTYgen to convert the keys to OpenSSH key format. Then, the keys can then be used with the SSH command to log into a Linux instance.
Navigate to your PuTTY private key file (.ppk) and then click Open.
(Optional) Enter a key passphrase.
Click Conversions and then click Export OpenSSH key.
If you did not use as passphrase, click Yes at the PuTTYgen Warning to proceed.
In the Save private key as: window enter a file name for the converted key and then click Save.
You can now use the converted key to log into your Linux instance.
SSH Fails with Error: "Authentication Refused: Bad Ownership Or Modes For Directory " 🔗
This error occurs because incorrect permissions are set on the /home/<USERNAME> directory or the .ssh/authorized_keys file.
Note
The example home directory paths in this troubleshooting tip use Oracle Linux. The home path may differ based on the operating system. For example, the home path in MacOS is /Users/<USERNAME>.
Set correct Permissions
If you have incorrect permissions set on the /home/<USERNAME> directory or the .ssh/authorized_keys file, connecting to a Linux instance using SSH can fail.
For example:
login as: <username>
Server refused our key
If you review the /var/log/secure log files on the Linux instance, you see the reason for the error:
<SERVER> sshd[6245]: Authentication refused: bad ownership or modes for directory /home/<USERNAME>
To correct the error, set the permissions on the home directory or .ssh/authorized_keys file, use the chmod command:
OCI
Cloud Shell is a web browser-based terminal accessible from the OCI
Console. Cloud Shell is free to use (within monthly tenancy limits), and provides access to a Linux shell, with a pre-authenticated OCI CLI, a pre-authenticated Ansible installation, and other useful tools.
If you are having connectivity issues with your instance, Cloud Shell is an effective option for connecting with SSH. Since Cloud Shell is browser based, it eliminates any potential connectivity issues due to laptop or corporate firewall settings. This section links you to the information about the ways you can use Cloud Shell.
If this is your first time creating an instance, we recommend creating a Virtual Cloud Network (VCN) first. You can use the "Start VCN Wizard" workflow and select the "Create VCN with Internet Connectivity" option. The workflow creates a VCN which automatically configures both a public and a private subnet along with any required gateways and route rules. In addition, the workflow provides an option to configure IPv6. For details on running the workflow see: Virtual Networking Quickstart.
(2) The Instance is intentionally on a Private Subnet
When the Compute instance is on a private subnet, you can connect to it using:
Bastion provides restricted and time-limited access to target resources that don't have public endpoints. See the Bastion Overview for more details.
Additional Connection and Instance Troubleshooting Options 🔗
The focus of this page is using the SSH command to connect to an instance. Here are other tools available to troubleshoot Compute instances.
Troubleshooting with the Serial Console 🔗
Using an OCI console connection, you can use the instance's serial console to connect to the instance. This allows you to remotely troubleshoot and configure an instance. For more information, see Troubleshooting Instances Using Instance Console Connections.
From the serial console, you can perform the following administrative tasks:
On the instance details page, you can observe metrics related to the instance including the instance's health. The oci_compute_instance_health metric lets you monitor whether a VM instance is unresponsive. Compute sends an Address Resolution Protocol (ARP) request to the instance's virtual network interface card (VNIC). If the ARP ping fails, the metric shows that the instance is unresponsive.
To use the metric, select oci_compute_instance_health from the Metric namespace control on the details page. For more information, see: Compute Instance Health Metrics.
Other Compute Troubleshooting Sections 🔗
In addition to SSH, the following troubleshooting topics are also available.