Unable to SSH/gcloud into default Google Deep Learning VM

446 Views Asked by At

I created a new Google Deep Learning VM keeping all the defaults except for asking no GPU:

enter image description here

The VM instance was successfully launched:

enter image description here

But I cannot SSH into it:

enter image description here

Same issue when attempting to use with gcloud (using the command provided when clicking on the instance's arrow down button at the right of SSH):

enter image description here

ssh: connect to host 34.105.108.43 port 22: Connection timed out
ERROR: (gcloud.beta.compute.ssh) [/usr/bin/ssh] exited with return code [255].

enter image description here

Why?


VM instance details:

enter image description here

3

There are 3 best solutions below

0
On BEST ANSWER

In order to connect to the VM Instance you will have to follow the guide from GCP and then set up the role with the necessary authorization under IAM & Admin.

0
On

Turns out that the browser-based SSH client and browser-based gcloud client were disabled by my organization, this is why I couldn't access the VM. The reason I was given is that to allow browser-based SSH, one would have to expose the VMs to the entire web, because Google does not provide a list of the IPs they use for browser-based SSH.

So instead one can SSH into a GCP VM via one's local SSH client by first uploading one's SSH key using the GCP web console. See https://cloud.google.com/compute/docs/instances/connecting-advanced#linux-macos (mirror) for the documentation on how to use one's local SSH client with GCP.


Since the documentation can be a bit tedious to parse, here are the commands I run on my local Ubuntu 18.04 LTS x64 to upload my SSH key and connect to the VM:

If you haven't installed gcloud yet:

# https://cloud.google.com/sdk/docs/install#linux (<- go there to get the latest gcloud URL to download via curl):
sudo apt-get install -y curl
curl -O https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-310.0.0-linux-x86_64.tar.gz
tar -xvf google-cloud-sdk-310.0.0-linux-x86_64.tar.gz./google-cloud-sdk/install.sh
./google-cloud-sdk/bin/gcloud init

Once gcloud is installed:

# Connect to gcloud
gcloud auth login
# Retrieve one's GCP "username"
gcloud compute os-login describe-profile
# The output will be "name: '[some large number, which is the username]'"
# Create a new SSH key
ssh-keygen -t rsa -f ~/.ssh/gcp001 -C USERNAME
chmod 400 ~/.ssh/gcp001
# if you want to view the public key: nano ~/.ssh/gcp001.pub
gcloud compute os-login ssh-keys add --key-file ~/.ssh/gcp001.pub
gcloud compute ssh --project PROJECT_ID --zone ZONE VM_NAME
# Note that PROJECT_ID can be viewed when running `gcloud auth login`, 
# which will output "Your current project has been set to: [PROJECT_ID]".

0
On

Please do:

  • sudo gcloud compute config-ssh
  • gcloud auth login

Login to your Gmail account. Accept access of Google Cloud.

Later set project if not yet done:

  • gcloud config set project YOU-PROJECT-ID

Run gcloud compute ssh with all you need.

If you still have a problem, please remove this:

  • rm .ssh/google_compute_engine

Run gcloud compute ssh with all you need again and the issue should be solved!