SSH zu Google Cloud VM-Instanz über Kommandozeile
Wenn du dich mit SSH von deiner Kommandozeile mit einer Google Cloud VM-Instanz verbinden möchtest (my-instance in diesem Beispiel), hast du zwei Optionen:
Direkt mit gcloud verbinden
Dies wird immer funktionieren, wenn deine Instanz SSH aktiviert hat, auch wenn sie keine externe IP hat:
gcloud compute ssh my-instance --zone $(gcloud compute instances list --filter="name=my-instance" --format "get(zone)" | awk -F/ '{print $NF}')Note that your have to replace my-instance by your actual instance name two times in the command above. The subcommand (enclosed in $(...) ) finds the correct zone for your instance since at the time of writing this article gcloud compute ssh will not work unless you set the correct zone for that instance. See How to find zone of Google Cloud VM instance on command line for more details.
Über externe IP verbinden
Du kannst auch gcloud verwenden, um die externe IP zu erhalten und dich mit deinem Standard-SSH-Client damit zu verbinden.
ssh $(gcloud compute instances list --filter="name=my-instance" --format "get(networkInterfaces[0].accessConfigs[0].natIP)")Dies hat den zusätzlichen Vorteil, dass du dies in anderen SSH-ähnlichen Befehlen wie rsync verwenden kannst.
For reference also see the official manual on Securely Connecting to Instances