-3

I am using the below command for SSH to GCP VMs. How can I configure VSCode to use these settings?

gcloud beta compute ssh --zone "asia-south1-a" "jump-box" --tunnel-through-iap --project "Project Name"

(editor note: notice --tunnel-through-iap in particular)

ZachB
  • 13,051
  • 4
  • 61
  • 89
karan bhatia
  • 155
  • 2
  • 8
  • 3
    It might be just me ... but I don't know what you mean by "... configure this as per remote SSH config?" ... could you elaborate on what you mean by that? – Kolban May 11 '22 at 13:09

2 Answers2

0

Given the title I'm guessing what you're trying to do is use a compute ssh command for https://code.visualstudio.com/docs/remote/ssh

I couldn't find a way to use this directly, but a workaround that I found is to run:

gcloud compute config-ssh --dry-run --project "Project Name"

This will produce an SSH configuration for all the instances in your project.

I was then able to add the hosts I was interested to my vscode ssh config (~/.ssh/config by default). It'll be something like this, but I've redacted the bits related to my project.

Host INSTANCE-NAME.ZONE.PROJECT_NAME
    HostName IP
    IdentityFile /Users/USER/.ssh/google_compute_engine
    UserKnownHostsFile=/Users/USER/.ssh/google_compute_known_hosts
    HostKeyAlias=compute.ID
    IdentitiesOnly=yes
    CheckHostIP=no

You could also omit the --dry-run to automatically add the entries.

Mat Schaffer
  • 1,634
  • 1
  • 15
  • 24
0

https://medium.com/@albert.brand/remote-to-a-vm-over-an-iap-tunnel-with-vscode-f9fb54676153 provides a tutorial. Briefly, add --dry-run to your normal gcloud compute ssh command to see what gcloud is doing under the hood. Those options need to get set in your VSCode SSH config file.

When using --tunnel-through-iap, you'll see a few ProxyCommand that invokes gcloud.py, and HostName and HostKeyAlias set to the instance ID (looks like compute.123456789123456789), as well as a few others.

ZachB
  • 13,051
  • 4
  • 61
  • 89