SYCK playz
SYCK playz

Reputation: 112

GCP browser ssh stops working after a week or so

I use the GCP browser ssh to host my python file. After a week or so, the ssh of the VM Instance stops and when I try to connect to it, first it shows

Connection via Cloud Identity-Aware Proxy Failed
Code: 4003
Reason: failed to connect to backend
You may be able to connect without using the Cloud Identity-Aware Proxy.

when I try to connect without using the Cloud Identity-Aware Proxy it gives me this error

Connection Failed
We are unable to connect to the VM on port 22. Learn more about possible causes of this issue.

I don't think I changed those settings that cause this.

EDIT 1

I found out its a firewall issue. I made a firewall rule that did allow to connect to port 22 but it still gave the same error.

EDIT 2

A day after I made the firewall rule, now, the Instance started working again. I was able to access the SSH.

Upvotes: 0

Views: 621

Answers (1)

Jose Luis Delgadillo
Jose Luis Delgadillo

Reputation: 2448

Regarding the problem with your SSH, the error code 4003, this error could have many explanations:

  1. Your instance can’t start the ssh service.
  2. Your firewall is not configured properly to allow the port 22.
  3. You have modified something in your instance and your metadata stopped working.

If your instance is running well,we could check points 1 and 2 using a port scanner, we could check tough port 22 for ssh if it is reachable. If it is not in green it means that it could be a problem in the firewall or with the SSH service.

enter image description here

If you have problems with your firewall, please check this documentation to create the proper rules.

If the problem is with your metadata it could be necessary to Install the guest environment in-place, you could validate if the guest environment is working by inspecting system logs emitted to the console while an instance starts up, please check this document of Validating the guest environment for more information.

You should see something like Started Google Compute Engine Startup Scripts. if your metadata is working properly (I test it in Ubuntu).

Since you are not able to connect to the instance via SSH button, you have to enable the serial console of this vm instance to get into the command line of the vm instance.

Please try to create a startup-script to create a user and password and with this login in the VM from serial ports, the script would be like this:

  1. Go to the VM instances page in Google Cloud Platform console.
  2. Click on the instance for which you want to add a startup script.
  3. Click the Edit button at the top of the page.
  4. Click on Enable connecting to serial ports
  5. Under Custom metadata, click Add item.
  6. Set 'Key' to 'startup-script' and set 'Value' to this script:
#! /bin/bash 
useradd -G sudo <user>
echo '<user>:<password>' | chpasswd
  1. Click Save and then click RESET on the top of the page. You might need to wait for some time for the instance to reboot.
  2. Click on ”Connect to serial port” on the page.
  3. In the new window, you might need to wait a bit and press Enter on your keyboard once; then, you should see the login prompt.
  4. Login using the USERNAME and PASSWORD you provided and you will be logged.

If your metadata is not working properly, you should to install the guest environment in your VM:

  1. Ensure that the version of your operating system is supported .
  2. Enable the Universe repository. Canonical publishes packages for its guest environment to the Universe repository.

sudo apt-add-repository universe

  1. Update package lists:

sudo apt update

  1. Install the guest environment packages:

sudo apt install -y gce-compute-image-packages

  1. Restart the instance and inspect its console log to make sure the guest environment loads as it starts back up.
  2. Verify that you can connect to the instance using SSH.

Edit 1

Make sure you have an external IP or that you are following one of the options described here.

If your problem is related with CPU usage or your VM Instance is running out of memory, please consider changing the machine type.

Changing a machine type

1.- Go to the VM Instances page.

2.- In the Name column, click your instance.

  1. From the instance details page, complete the following steps:

    a) Click the Stop button to stop the instance, if you have not stopped it yet.

    b) After the instance stops, click the Edit button at the top of the page.

    c) Under the Machine configuration section, select the machine type you want to use, or create a custom machine type to increase only the Memory.

    d) Save your changes and start again your VM Instance.

Upvotes: 2

Related Questions