VSCode Remote SSH custom command to connect to GCE instance

29 Views Asked by At

Problem

I have an instance in GCE that I spin up when I start to work and down when I'm done for the day. I use VSCode to connect via SSH to the instance but, for this to work, I have to grab it's public IP and change my .ssh/config file manually. I want to avoid needing to grab the IP manually.

What I tried

I can directly SSH into the instance with this command gcloud compute ssh --zone=<zone> --ssh-key-file=~/.ssh/<key-file> <username>@<instance-name> --project=<project-id> -- -A", which works and doesn't require me to go get the IP, but doesn't work with VSCode.

I can also gcloud compute config-ssh --project=<project-id> --ssh-key-file=~/.ssh/<your-key-file>, which populates the .ssh/config file with IPs, but I have to run it each time and it populates configs for each running instance, not mine specifically.

I tried adding a new connection via VSCode's UI and, where it asks for the command, I tried the first example I gave but it gives Unknown flag zone.

0

There are 0 best solutions below