ERROR: (gcloud.compute.ssh) [/usr/bin/ssh] exited with return code [255]

I encountered the error:
ERROR: (gcloud.compute.ssh) [/usr/bin/ssh] exited with return code [255].
and get kicked out of google cloud instance after an idle of several seconds. I have googled around but found a no fix. Could you please help me with this?



This answer from stackoverflow worked for me. At least so far…
Since you’ve created a new user, when you will not be in the directory with the tutorials. You can run either of the following to get to the “jupyter” user directory.
cd …/jupyter/
cd /home/jupyter/

I have been having a lot of similar issues. Ive been getting the error message:
ssh: connect to host port 22: Connection refused ERROR: (gcloud.compute.ssh) [/usr/bin/ssh] exited with return code [255].

I have found the following solution to be working for me so far…

  1. In the GCP Console, go to the VM Instances page.
  2. Select the instance and click edit.
  3. Find Custom metadata option and Click Add item and Type startup-script as a key and Copy and past the command sudo ufw allow ssh as a value. This command will enabled port 22 for SSH.

people who are using terrafrom to create instance, may encounter similar issue even after public and private key all in place, even if you use default VPC…Reason being the the firewall rule has to be set on GCP .

From GUI , go to firewal rules , allow port ssh (22), Else check out terraform docs and add the firewall resource while creating VPC.

This worked for me.


I tired some things nothing worked. Then I went and started the instance in gcloud and then retried to connect and then it connected. Just went through lesson one, hope it works again today…

You need to $gcloud init with the correct configuration. This problem arises because you are using a different ssh configuration

Running sudo gcloud compute config-ssh fixed the issue for me.