GCP Error Unable to connect on port 22

+3 votes

While trying to connect to an Linux VM instance that I have configured on google cloud, I choose the method "SSH  in browser" but I can't connect to it. it shows this error:

Unable to connect on port 22

How should i troubleshoot this issue?

Sep 24, 2019 in GCP by anonymous
• 19,610 points
8,038 views

1 answer to this question.

+1 vote
Best answer

You may see this error under the following conditions:

  • The instance is booting up and sshd is not yet running. Verify that the instance has finished booting up before trying again.

  • The instance is not running sshd. sshd runs by default on instances created from standard Compute Engine images. If you have manually disabled sshd or you have configured a custom image that is not running this service, SSH from the Browser will not work.

  • sshd is listening on a port other than the one you are connecting to. By default, SSH from the Browser connects to the instance on port 22. If you are running sshd on a custom port, you can connect to that port using "Open in browser window on custom port" item in the SSH button drop-down menu.

  • There is no firewall rule allowing SSH access on the port. SSH access on port 22 is enabled on all Compute Engine instances by default. If you have disabled access, SSH from the Browser will not work. If you run sshd on a port other than 22, you need to enable the access to that port with a custom firewall rule.

  • The firewall rule allowing SSH access is enabled but is not configured to allow connections from GCP Console services. Source IP addresses for browser-based SSH sessions are dynamically allocated by GCP Console and can vary from session to session. For the feature to work, you must allow connections either from any IP address or from Google's IP address range which you can retrieve using public SPF records.

  • The instance is shut down. Verify that the instance is up and running. 

Hope this helps!

answered Sep 24, 2019 by Sirajul
• 59,230 points

selected Dec 4, 2019 by Kalgi
Hi SlraJul,

what does mean of second last point in your answer ?
Usually, our browser SSH sessions have IP addresses that are allocated by the GCP console and this IP address will change with every session that you create in your browser (dynamic).

You may already have a firewall rule that allows SSH but, it may not have any configuration to allow GCP console services.

So, in your firewall rule, you need to allow connections from any IP address or you could allow connections from Google's IP address range.

Hope this is clear!

Related Questions In GCP

0 votes
1 answer
0 votes
1 answer

Unable to install NVIDIA driver on various GCP Ubuntu VM's with Tesla K80 GPU

The mistake you are making here is ...READ MORE

answered Apr 5, 2022 in GCP by Korak
• 5,820 points
1,175 views
0 votes
1 answer

Creating a SQL Server instance using Google Compute engine.

Google Compute Engine provides public images preconfigured with ...READ MORE

answered Sep 23, 2019 in GCP by Sirajul
• 59,230 points
2,896 views
0 votes
1 answer
0 votes
1 answer

How do i install gcloud compute?

The gcloud compute command-line tool enables you to easily ...READ MORE

answered Sep 23, 2019 in GCP by Sirajul
• 59,230 points

edited Jun 16, 2023 by Khan Sarfaraz 1,244 views
0 votes
1 answer

How to allow outbound traffic on a custom port in gcp?

To allow outbound traffic through a custom ...READ MORE

answered Sep 26, 2019 in GCP by Sirajul
• 59,230 points
4,996 views
0 votes
1 answer

Cannot connect to my VM instance on GCP via SSH.

This might be because UFW is installed. ...READ MORE

answered Sep 27, 2019 in GCP by Sirajul
• 59,230 points
4,646 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP