Skip to content

Instantly share code, notes, and snippets.

@kholisrag
Last active March 22, 2024 04:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kholisrag/73870e5dbaac9dd5d8bdcec9920673e5 to your computer and use it in GitHub Desktop.
Save kholisrag/73870e5dbaac9dd5d8bdcec9920673e5 to your computer and use it in GitHub Desktop.
Generate SSH Config to make alias with gcp vm instances Internal IPs
#!/bin/bash
# Set the project ID
PROJECT_ID="XXXXXXXXX"
# Get instance information in JSON format
gcloud compute instances list \
--project "${PROJECT_ID}" \
--format="json" > ./instances.json
# Process the JSON using jq to extract relevant fields
jq -r '.[] | "Host \(.name)\n HostName \(.networkInterfaces[0].networkIP)\n"' instances.json
rm ./instances.json
# Copy Paste the output to the ~/.ssh/config file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment