Recover from firewall not allowing ssh on port 22 in GCP instance
1 min readApr 25, 2019
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 :
- 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
- Click Edit. Then, scroll down to Custom Metadata
- Create a new metadata field. Set the key to
startup-script
. Set value tosudo ufw allow 22
- Restart your VM
- Now,
ssh
to the instance. Now, you should be able to get access to the VM - 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