1

I'm working on some tutorials and trying to do something, but no idea if it can be done. I am using windows terminal in Windows 10. I have an Ubuntu virtual machine running.

I'd like to:

  1. Open Windows terminal
  2. SSH into the Linux Virtual Machine
  3. Type in the code . command and have it open a version of VS Code on my Windows PC that is working on the folder in the Ubuntu VM.

I tried install code locally and on the command line in the other machine, but it doesn't work. I am sure there are other ways to do this but wanted to explain how I was doing it to show I at least tried something. Thanks for your help.

Vaslo
  • 480
  • 1
  • 5
  • 22
  • 1
    i asked also some kind of the same question , https://stackoverflow.com/questions/65709446/debug-c-app-using-visual-studio-code-and-vagrant-runnig-ubuntu – user63898 Jan 14 '21 at 05:53

1 Answers1

1

It's not quite as easy as the code . technique you get with the Remote - WSL extension, but Microsoft also provides a Remote - SSH extension that can be used to directly access the remote machine (without requiring WSL in-the-middle).

Once the Remote - SSH extension is installed in VSCode (and it may have already been installed in an extension pack with the WSL extension), and you have installed an OpenSSH client in Windows, there are several ways to access files on the remote host through SSH:

  • From the Command Palette (Ctrl+Shift+P), type Remote SSH to filter on those commands. From Connect to Host, you can add a new configuration, etc.

  • From the Activity Bar on the left, select the Remote Explorer icon, then in the dropdown at the top, select SSH Targets. You can add hosts here through the + icon.

  • There's a direct shortcut to Open a Remote Window at the far left of the status bar. This will give you similar filter options on the Command Palette as above.

Once a host is configured, you can browse it just as (well, almost) if it were local, open files, edit, etc. The one thing you can't do (as far as I'm aware) is any type of sudo/su editing on files that you don't have permissions to directly.

Full details in the VSCode docs here.

NotTheDr01ds
  • 15,620
  • 5
  • 44
  • 70
  • 1
    i added the error im getting in the question https://stackoverflow.com/questions/65709446/debug-c-app-using-visual-studio-code-and-vagrant-runnig-ubuntu – user63898 Jan 14 '21 at 11:29
  • 1
    Note that this doesn't answer the question as stated, because they are wanting to know if opening VS Code directly from a terminal is possible when SSH'ed into a machine. – bmitc Sep 16 '22 at 15:42
  • @bmitc Right - I do address that in my first sentence ;-). As I said, it's not quite as easy as directly launching it via `code .` when `ssh`'d into a remote machine, but it's still possible indirectly. Also, the acceptance of the answer by the OP would seem to indicate that it *was* a sufficient workaround. – NotTheDr01ds Sep 16 '22 at 16:33
  • 1
    True. I just happened to be searching for a solution to the original problem. Haha. :) – bmitc Sep 16 '22 at 22:22
  • @bmitc If you are willing to install and use the Linux version of VSCode on the remote server, it should be possible to configure it to work with `code .` using X forwarding through SSH + WSL. If that's of interest to you, I can write up a separate answer. – NotTheDr01ds Sep 16 '22 at 23:13