Issue
I'm having a recurrent problem while using the Google Cloud Platform. To illustrate what's happening I created a new VM, successfully connected to it via gcloud beta compute ssh
, and suspended the instance.
After it was suspended, I resumed it, but wasn't able to connect to it via ssh anymore, I ran the command:
gcloud beta compute ssh --zone "us-central1-a" "test-vm" --project "my-project" --ssh-flag="-vvv"
and received the following output:
OpenSSH_7.6p1 Ubuntu-4ubuntu0.3, OpenSSL 1.0.2n 7 Dec 2017
debug1: Reading configuration data /home/guilherme/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug2: resolving "34.66.57.82" port 22
debug2: ssh_connect_direct: needpriv 0
debug1: Connecting to 34.66.57.82 [34.66.57.82] port 22.
debug1: connect to address 34.66.57.82 port 22: Connection timed out
ssh: connect to host 34.66.57.82 port 22: Connection timed out
ERROR: (gcloud.beta.compute.ssh) [/usr/bin/ssh] exited with return code [255].
The suspend/resume was done in browser, on GCP's platform.
Because of this problem I have not been able to suspend any VMs, since I "lose" it everytime. Does anyone know how to properly suspend it? Thanks
Solution
If there was a change in the setup "gcloud" denies an ssh connection, you must update the ssh keys in your metadata by:
sudo gcloud compute config-ssh
If this complains about different entries in your config file where your ssh key entries are stored, ~/.ssh/config, delete this file and execute the above command again.
If the internal firewall of the system block port 22, you can try the following steps to fix it:
- In the GCP Console, go to the VM Instances.
- Select the instance and click edit.
- 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.
Recommend this topic Troubleshooting SSH for your issue.
Answered By - William