Recover from firewall not allowing ssh on port 22 in GCP instance

Prashant Shahi
1 min readApr 25, 2019

--

Image source: guidingtech.com

Tried to setup UFW or any other Firewall, but it disallows any traffic to port 22, which doesn't let you ssh to your Google Cloud Platform (GCP) instance? 😖

This article might be your savior. 😎

Follow the instructions below :

  1. Go to your VM’s configuration page. Select the project. Then, Go to Compute -> Compute Engine -> VM Instances. Click the VM you want to recover
  2. Click Edit. Then, scroll down to Custom Metadata
  3. Create a new metadata field. Set the key to startup-script. Set value to sudo ufw allow 22
  4. Restart your VM
  5. Now, ssh to the instance. Now, you should be able to get access to the VM
  6. Heave a sigh of relief 😌

For AWS, the method is quite similar. But instead of startup-script , we need to specify the script in theUser Data field. Read more about it here.

Originally posted on https://gist.github.com/prashant-shahi/a207c4fbd12772c7b264acc43c6ea944

--

--

Responses (1)