Skip to content

Instantly share code, notes, and snippets.

@ronniejoshua
Last active June 9, 2021 15:05
Show Gist options
  • Save ronniejoshua/f9bd671cc214b31e0fc3ecd195d64198 to your computer and use it in GitHub Desktop.
Save ronniejoshua/f9bd671cc214b31e0fc3ecd195d64198 to your computer and use it in GitHub Desktop.
Automate external ip white listing and connecting to gcp compute engine using shell script
#!/bin/bash
GCLOUD="/Users/<your-username>/google-cloud-sdk/bin"
${GCLOUD}/gcloud compute firewall-rules update <gcp-firewall-rule-name> --project=<gcp-project-id> --source-ranges=$(curl ifconfig.me)
external_ip=$(${GCLOUD}/gcloud compute instances describe <gcp-compute-engine> --zone=<gcp-ce-zone> --format='get(networkInterfaces[0].accessConfigs[0].natIP)')
ssh naya@$external_ip -p 122
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment