Can't SSH connect to Google Cloud Compute Engine after rebooting

2.4k views Asked by At

I just restarted my google cloud compute engine instance and now I cannot SSH login to it. Before restarting, it worked fine. I tried fully stopping it and then starting again. There was a webserver on it and if I try to access any API method, I get timeout.

If I try to login from console website: enter image description here

If I try to login from terminal:

ssh: connect to host 104.197.20.65 port 22: Operation timed out
ERROR: (gcloud.compute.ssh) [/usr/bin/ssh] exited with return code [255]. See https://cloud.google.com/compute/docs/troubleshooting#ssherrors for troubleshooting hints.

What is wrong?

2

There are 2 answers

0
Fanco On

I had the same problem, and tried lots of way but none of them work.

But the way below is work for me:

  1. Connect to instance by serial console.
  2. vi /etc/ssh/sshd_config, delete the hash tag before Port 22, like this:
Port 22
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::

Hope it work for you too.

0
Nilo_DS On

As the error message suggest the first thing to do is check the firewall rules. There must be a rule allowing connections from any ip (0.0.0.0/0) through the port 22. I assume that your instance's ssh was working before, so it can be two things.

  1. The rule is being applied to a certain network, and the network configuration of the VM was changed when it was shutted down.

  2. The rule is not being applied to the VM, maybe it is in a subnetwork, closing the communication.

To simplify the solution:

A- Add a network tag to your VM. (Ex. ssh-conn) https://cloud.google.com/compute/docs/vpc/add-remove-network-tags

B- Create a rule to allow connections from any ip and apply it to the network tag previously created. https://cloud.google.com/compute/docs/vpc/using-firewalls