GCP: Unable to connect to Datalab - google-cloud-platform

I'm trying to connect to the datalab using the following command:
datalab connect <datalab name> --no-user-checking
it gives the following error message:
Connecting to <datalab name>.
This will create an SSH tunnel and may prompt you to create an rsa key pair. To manage these keys, see https://cloud.google.com/compute/docs/instances/adding-removing-ssh-keys
Waiting for Datalab to be reachable at http://localhost:8081/
bind: Address already in use
channel_setup_fwd_listener_tcpip: cannot listen to port: 8081
Could not request local forwarding.
Could someone please help me resolve the issue?
Thanks a lot.

This issue is usually generated when another Datalab or external process is running in the background by using the port 8081. You can kill the existing process or reset the machine where the tunnel to Datalab is running on.
In case you are using Cloud Shell, you can reset it by clicking the "Options" button next to the "Web Preview" button and clicking on Restart option. Afterwards, try to connect again the the Datalab instance:
datalab connect <datalab name> --port 8081

Related

How to troubleshoot google cloud instance issue

I have a google VM instance that stopped working sometime in the last 4 days. The last time I tried to access it, everything was fine. By 'stopped working' I mean:
Unable to connect to websites hosted at that instance
Unable to connect to the instance using gcloud compute ssh
I can connect to the instance by opening an ssh terminal in a browser window from within console.gcloud.google.com.
Running gcloud compute ssh from my local terminal results in:
ssh: connect to host 34.69.41.204 port 22: Operation timed out
ERROR: (gcloud.compute.ssh) [/usr/bin/ssh] exited with return code [255].
Connecting over http results in:
wget http://panam.whensparksfly.org
--2021-10-11 11:18:00-- http://panam.whensparksfly.org/
Resolving panam.whensparksfly.org (panam.whensparksfly.org)... 34.69.41.204
Connecting to panam.whensparksfly.org (panam.whensparksfly.org)|34.69.41.204|:80... failed: Operation timed out.
If I run that same wget command from the browser-based terminal I started from https://console.gcloud.google.com, it works.
I've tried stopping and restarting the instance. I also have another instance that I usually leave off. I started that instance and had the same problem.
Here are the firewall rules for that instance:
How should I go about troubleshooting this?
This is not an answer to my specific question about how to troubleshoot the problem, but here's how I resolved the issue:
Create a new machine image from the original instance
Create a new instance from the machine image. Go to the Machine Images page in the Google Cloud Console, click the Actions button for the desired image, then click create instance.
I was able to transfer my static external IP address to the new instance by following the instructions here.
Everything is now working as before.

Unable to login to a GCP VM machine: kex_exchange_identification: Connection closed by remote host

I am trying to login to a VM machine but unable to get in there as the below error pops up:
ERROR: (gcloud.beta.compute.start-iap-tunnel) Error while connecting [[Errno 1] Operation not permitted].
kex_exchange_identification: Connection closed by remote host
ERROR: (gcloud.beta.compute.ssh) [/usr/bin/ssh] exited with return code [255].
Command used to log in:
gcloud beta compute ssh --zone "us-east1-b" "user1#test" --project "my-test-project"
When I use the same command from a different machine then it allows me to login to the test VM.
I have been looking at possible solutions related to the firewall settings but unable to get success. Can anyone help here ?
I try to connect with an instance with the command that you post and worked for me when I use it from the cloud shell and from another instances. The error that is given to you could happen for different reason, which are:
The VM is booting up and sshd is not running yet. You can't connect to a VM before it is running.
To resolve this issue, wait until the VM has finished booting and try to connect again.
The firewall rule allowing SSH is missing or misconfigured. By default, Compute Engine VMs allow SSH access on port 22. If the default-allow-ssh rule is missing or misconfigured, you won't be able to connect to VMs.
To resolve this issue, Check your firewall rules and re-add or reconfigure default-allow-ssh.
sshd is running on a custom port. If you configured sshd to run on a port other than port 22, you won't be able to connect to your VM. To resolve this issue, create a custom firewall rule allowing tcp traffic on the port that your sshd is running on using the following command:
gcloud compute firewall-rules create FIREWALL_NAME --allow tcp:PORT_NUMBER
Your custom SSH firewall rule doesn't allow traffic from Google services. SSH connections from the Cloud Console are refused if custom firewall rules do not allow connections from Google's IP address range.
To solve this issue visit this link
The sshd daemon isn't running or isn't configured properly. The sshd daemon enables SSH connections. If it's misconfigured or not running, you can't connect to your VM. To resolve this issue, review the user guide for your operating system to ensure that your sshd_config is set up correctly.

I can't open mi VM by SSH

I have acquired on the marketplace a solution for Ubuntu Trusty, I've create my VM, I just changed the name and try to open by SSH I can't get a connection. This is the error:
"Could not connect to the VM on port 22. Learn about the possible causes of this problem."
One year ago I created a VM and I didn't have troubles, now I don't know why just I can't...
If there was a change in the setup "gcloud" denies an ssh connection, you must update the ssh keys in your metadata:
sudo gcloud compute config-ssh
If the internal firewall of the system block port 22, you can try the following steps to fix it:
Shut down the instance
Click 'Edit' for the instance, under 'Custom Metadata' section, add 'startup-script' key, with value:
#! /bin/bash
sudo ufw allow 22
Click 'Save'
Start the instance again, and SSH into it

Creating Notebook Failed - An error ocurred while creating a new notebook GOOGLE CLOUD DATALAB

In GCP. According to this Article, https://mohameddhaoui.github.io/dataengineering/chatbot3/
I created a new google cloud datalab instance, and run it on port 8081. When I go to Google Cloud Datalab and click on add note, the following error is presented.
Datalab Error PrintScreen
I am the owner of the account and have full access to the resources.
This is the command I used to deploy the datalab instance:
datalab create datalab-instance
The result of the execution is as follows.
This will create an SSH tunnel and may prompt you to create an rsa key pair. To manage these keys, see https://cloud.google.com/compute/docs/instances/adding-removing-ssh-keys
Waiting for Datalab to be reachable at http://localhost:8081/
ssh: connect to host 35.229.109.170 port 22: Connection refused
ERROR: (gcloud.compute.ssh) [/usr/bin/ssh] exited with return code [255].
Connection closed
Attempting to reconnect...
Waiting for Datalab to be reachable at http://localhost:8081/
Enter passphrase for key '/home/myuserXXX/.ssh/google_compute_engine':
The connection to Datalab is now open and will remain until this command is killed.
Click on the Web Preview (square button at top-right), select Change port > Port 8081, and start using Datalab.
Your help will be very appreciated.
Best Regards

Google Cloud Instances Firewall Unable to Login SSH

I logged to my ssh in google cloud Linux Machine by mistake i changed firewall rule and i lost ssh connection. now i am not able login to ssh(22), Is there any way to recover that ?
I know I can take shanpshots of my machine and create new instances using that snapshot. but is there anyway to get again ssh login in same machine or i have to delete it.
Try connecting to the instance via the serial console: https://cloud.google.com/compute/docs/instances/interacting-with-serial-console. From there you should be able to repair the firewall rules.
pjhsea I tried your steps and it is connecting to serial port but it asks passphrase. I was not sure where I have given this passphrase. If you try to access serial port on gcloud console then it always asks for passphrase.
So I tried below steps and I was able to connect to serial port to change firewall setting on my ubuntu VM.
Goto Compute Engine -> VM Instances fro left side menu.
Click on name of the VM you are facing issue connecting using SSH.
It will open VM Instance details page.
On details tab under VM name there will be two dropdown for remote access.
SSH and Connect to serial console.
Click on serial console and select serial port 1(console)
This connect to serial console without any passphrase and I was able to change my firewall rules using below command.
ufw allow 22
Now you should be able to connect using SSH.