For some reason ssh
doesn't work to set up a tunnel to my Google Compute Engine instance. I have to use gcloud compute ssh
. I'd really like to set up a persistent/resilient tunnel, like one gets with autossh. Is there any way I can do so using gcloud compute ssh
?
Asked
Active
Viewed 1,028 times
1

brandones
- 1,847
- 2
- 18
- 36
1 Answers
5
gcloud compute ssh
simply copies your ssh key to the project sshKeys
metadata (see Cloud Console > Compute Engine > Metadata > SSH Keys) and runs standalone SSH with the ~/.ssh/google_compute_engine
key. To see the exact command line invoked, run gcloud compute ssh --dry-run ...
. Anything that's possible with typical SSH is possible with gcloud compute ssh
.
Another option to investigate is gcloud compute config-ssh
, which syncs your ~/.ssh/google_compute_engine
SSH key to the project and sets up your ~/.ssh/config
file so that you can run ssh
without gcloud
.

Zachary Newman
- 20,014
- 4
- 39
- 37
-
1Note that `gcloud compute config-ssh` only works for instances with public IPs, i.e. it's N/A for those of us who rely on IAP (Identity Aware Proxy). Regarding `--dry-run` - it's pretty neat, just note when used with IAP the command it outputs can't be used verbatim as it's missing quotes and "=" in `ProxyCommand` (at least as of gcloud version 283.0.0) Should anyone encounter this, the syntax printed is `-o ProxyCommand /usr/bin/python3 -S ... -o ...` while it should be `-o ProxyCommand="/usr/bin/python3 -S ..." -o ...` – Jean Spector Mar 05 '20 at 12:01