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

google-cloud-platformsshufw

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 tried the answer I found in this forum : Google cloud unable to connect to the VM on port 22

I followed the following instruction but it still not working:

  1. Shut down the instance
  2. Click 'Edit' for the instance
  3. Under 'Custom Metadata' section, add 'startup-script' key, with value:

#! /bin/bash
sudo ufw allow 22

  1. Click 'Save'

Can anyone help, I'll be appreciate!

My GCP Custom Metadata setting picture

Best Answer

If you were able to SSH before setting these OS FW rules. Restore UFW

ufw reset

sudo ufw default deny incoming

sudo ufw default allow outgoing

And then enable the SHH on the default port 22:

sudo ufw allow 22

sudo ufw enable

Be sure if you are using the default port number 22 or a different one. Follow these instructon if you are able to ssh without AFW.

https://cloud.google.com/compute/docs/troubleshooting/troubleshooting-ssh