Search code examples
sshgoogle-compute-engineufw

GCP Connection Failed - SSH - We are unable to connect to the VM on port 22


Since I received a email warning letter from google says "Action required: Critical problem with My First Project" saying my server has some abnormal outgoing activity , I tried to implemented ufw in my debian server.

For my ufw setting, I've done the following:

sudo ufw default deny incoming 
sudo ufw default deny outgoing
sudo ufw allow ssh
sudo ufw allow 22
sudo ufw allow http
sudo ufw allow https

After I restart my server , I can't connect to my server with the error "Connection Failed: We are unable to connect to the VM on port 22. Learn more about possible causes of this issue."

I followed the following instruction https://cloud.google.com/compute/docs/troubleshooting/troubleshooting-ssh but it still not working:

  1. I tried gcloud to create default-allow-ssh my firewall-rules list picture
  2. I tried to use serial console to login but I haven't set password to my root account so I can't login.
  3. I tried to add "/usr/sbin/ufw disable" to startup-script in Custom metadata and restart server many times but it seems the command is not executed so still not working my gcp startup-script picture

Solution

  • I found the correct answer in this website. https://www.jhanley.com/google-cloud-recovering-from-ufw-lockout/

    Method 2 in the website solves this problem