Last active
March 22, 2024 04:17
-
-
Save kholisrag/73870e5dbaac9dd5d8bdcec9920673e5 to your computer and use it in GitHub Desktop.
Generate SSH Config to make alias with gcp vm instances Internal IPs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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