a nifty script for accessing with native SSH (as opposed to gcloud compute ssh
) your IAP allowed Compute Engine instances (even when they don't have public IPs)
bash <(curl -fgsSL bit.ly/ssh-gcp) INSTANCE_NAME # TBD
bash <(curl -fgsSL bit.ly/ssh-gcp) INSTANCE_NAME.ZONE # TBD
bash <(curl -fgsSL bit.ly/ssh-gcp) INSTANCE_NAME.ZONE.PROJECT
bash <(curl -fgsSL bit.ly/ssh-gcp) INSTANCE_NAME.ZONE.c.PROJECT.internal # TBD
-
Download and copy the script to
~/.ssh/gcp-start-iap-tunnel-ssh-proxy-magic.sh
-
Add the following lines to
~/.ssh/config
:
# Google Cloud Compute Engine full SSH via using `gcloud compute start-iap-tunnel` as ProxyCommand
# (consider using this alongside `gcloud compute config-ssh`)
Host *.*-*-*.*
ProxyCommand sh ~/.ssh/gcp-start-iap-tunnel-ssh-proxy-magic.sh gce_instance=%n sshuser=%r sshport=%p
-
Use the
gcloud compute config-ssh --project=...
command to configure ssh host aliases for Compute Engine instances. -
Enjoy SSH (esp. scp, rsync) for any instances allowed for IAP with no extra effort.
$ scp myhost.us-west1-a.my-gcp-project:remote/path local/path
$ rsync -av myhost.us-west1-a.my-gcp-project:remote/ local/
$ ssh myhost.us-west1-a.my-gcp-project