Recover from firewall not allowing ssh on port 22 in GCP instance
By Prashant Shahi
- 1 minutes read - 156 wordsTried 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) or Aamazon Web Services (AWS) 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 to sudo 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 EC2 Instance, the method is quite similar. But instead of
startup-script
, we need to specify the script in the User Data field. Read more about it here.
Originally posted in https://medium.com/@coolboi567/recover-from-firewall-not-allowing-ssh-on-port-22-in-gcp-instance-1379fc84522e