I use gcloud compute ssh
to SSH into my instance, e.g.:
$ gcloud compute ssh shell-server --project=XXXXXXXXXXXXXXXX
No zone specified. Using zone [us-central1-f] for instance: [shell-server].
External IP address was not found; defaulting to using IAP tunneling.
Please choose from the available authentication methods:
1: Security code from Google Authenticator application
2: Voice or text message verification code
Enter the number for the authentication method to use: 1
Enter your one-time password: XXXXXX
username@shell-server ~ $
Unfortunately, I have to 2FA every time. I like 2FA, but maybe there's a way to set things up so that I only have to provided it every few hours?
Update: I ran gcloud compute ssh --dry-run
, which tells you exactly what command it's running:
/usr/bin/ssh \
-t \
-i /Users/kannan/.ssh/google_compute_engine \
-o CheckHostIP=no \
-o HostKeyAlias=compute.123123123123123123 \
-o IdentitiesOnly=yes \
-o StrictHostKeyChecking=no \
-o UserKnownHostsFile=/Users/kannan/.ssh/google_compute_known_hosts \
-o ProxyCommand='/usr/local/bin/python3 -S /Users/kannan/Software/google-cloud-sdk/lib/gcloud.py compute start-iap-tunnel shell-server %p --listen-on-stdin --project=XXXXXXXXXX --zone=us-central1-f --verbosity=warning' \
-o ProxyUseFdpass=no \
[email protected]
Update 2: I could keep gcloud compute start-iap-tunnel
running in the background and configure my SSH to use that tunnel, but I'm hoping for something more automatic, similar to the convenience of SSH's ControlMaster=auto
.