connecting vs code to gcp cloudshell via ss

Viewed 1283

I'm trying to connect vscode to cloud shell through ssh. I found the following article https://medium.com/@alex.burdenko/vs-code-happens-to-be-my-favorite-code-editor-and-ive-been-lucky-to-participate-so-many-diverse-952102856a7a. I followed all the steps and I'm able to ssh via the command line. However when I try to ssh via vscode I get an error.

This is what I have specified in the config file

Host tmp_user@35.186.145.21
   Port 6000
   ForwardAgent yes
   HostName tmp_user@35.186.145.21
   User tmp_user
   IdentityFile ~/.ssh/google_compute_engine

When I execute gcloud alpha cloud-shell ssh --dry-run I get the following

/user/bin/ssh -t -p 6000 -i /home/tmpus/.ssh/google_compute_engine -o StrictHostKeyChecking=no tmp_user@35.186.145.21 -- DEVSHELL_PROJECT_ID=myprj 'bash -l'

3 Answers

Google's Cloud Code extension for VS Code should automatically connect you to Cloud Shell via SSH. You can use one of the documented links here to automatically install the extension and open a sample or you can install Cloud Code directly from the marketplace and utilize the command palette (ctrl/cmd-shift-p) to run Cloud Code: Open in Cloud Shell.... This will also create the requisite entry in your host file but please keep in mind that IPs, host names, etc are temporary and only valid while the instance of your Cloud Shell session is live. This is likely the reason your connection fails with access is denied.

Remove "tmp_user@" from the HostName field.

Try this:

Host tmp_user@35.186.145.21
   Port 6000
   ForwardAgent yes
   HostName 35.186.145.21
   User tmp_user
   IdentityFile ~/.ssh/google_compute_engine

When you create cloud shell with

gcloud cloud-shell ssh --authorize-session --dry-run

In the answer you have something like this:

/usr/bin/ssh -t -p 6000 -i /home/tmp_user/.ssh/google_compute_engine -o StrictHostKeyChecking=no tmp_user@35.186.145.21 -- DEVSHELL_PROJECT_ID=XXXXXXXX 'bash -l'

So you add StrictHostKeyChecking parameter (UserKnownHostsFile /dev/null because it's temporary).

Your config file is like this:

Host tmp_user@35.186.145.21
    Port 6000
    ForwardAgent yes
    HostName 35.186.145.21
    User tmp_user
    StrictHostKeyChecking no
    UserKnownHostsFile /dev/null
    IdentityFile ~/.ssh/google_compute_engine

Related