I would like to use my ssh config to use a google cloud cli (gcloud) to connect to google compute instances. (This is a follow-on to another question I asked, that had a working solution, but didn't address this part of my question)

The desired functionality is ssh <instance-name>.gc would connect me to the gcloud instance.

To connect to the gcloud instance I can run:

/home/me/google-cloud-sdk/bin/gcloud compute --project "myproject" ssh --zone "myzone" me@<instance-name>

So I added an entry to my .ssh/config:

Host *.gc
    ProxyCommand /home/me/google-cloud-sdk/bin/gcloud compute --project "myproject" ssh --zone "myzone" me@$(basename %h .gc)

I then run ssh <instance-name>.gc and get:

# ssh <instance-name>.gc
Pseudo-terminal will not be allocated because stdin is not a terminal.
-bash: line 1: $'SSH-2.0-OpenSSH_8.0\r': command not found

It seems to establish a connection, but I don't have a prompt to type at, so I press ctrl-c to kill it.

I could make an alias to achieve similar behavior, but I want to be able to use it with other entries in my ssh config, so I can use it as a jumpbox.


It could be that I am misusing ProxyCommand, I get the same behavior if I replace the gcloud command with ssh me@<instace-ip> in the config file. If this is the case, is there an alternative config that help me to achieve my goal?

gcloud uses ssh under the hood, you can pass arguments to ssh after adding a --. I have tried adding a -- -t to force pseudo-terminal allocation, without change.

1 Answer 1


I figured out some working syntax, maybe it could be cleaned up, but it works.

Host *.gc
    User me
    ProxyCommand gcloud compute --project "myproject" ssh --zone "myzone" me@$(basename %h .gc) --command="nc 22"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.