1

When I SSH into my development VM and want to open something in VSCode, I cannot do so from the command line. Obviously that makes sense because the code command runs on the remote server which has no idea about the host.

When running code from a VSCode integrated terminal using the SSH plugin will however open another VSCode window for that remote folder.

Is it possible to run a command (like code ./foldername) on my SSH connection and have that command do something on the host (e.g. open VSCode)? From a normal terminal window over SSH? Does such a thing exist?

Giacomo1968
  • 53,069
  • 19
  • 162
  • 212
David Alsh
  • 315
  • 3
  • 12
  • 1
    Why would you want to do that? Your code on your local machine should be for development and code on a remote server should be just that: Deployed code. In the world of modern programming, you should be able to develop locally and just shoot code to a server. What you are describing is effectively attempting to jump through hoops for what benefit? – Giacomo1968 Apr 03 '21 at 03:50
  • 1
    My development environment is inside a virtual machine. I use vscode locally and connect to the vm using ssh. I'm essentially trying to achieve a hand-rolled wsl2 – David Alsh Apr 03 '21 at 03:52
  • 2
    Okay, that makes sense. I edited your question to clarify that. Wanting to do this with a local VM is a different thing from just a generic remote server access with the same goal. If not technically but at least conceptually; the value is clearer and valid if the VM is stated as the “remote” machine. – Giacomo1968 Apr 03 '21 at 04:08
  • That makes sense, thanks – David Alsh Apr 03 '21 at 04:21
  • Still unclear: Where do you want VSCode to run, where is the project, where do you want to enter the command? (Add to your comment `@harrymc` for me to be notified.) – harrymc Apr 03 '21 at 08:48
  • @harrymc The development environment is on their VM. They want to be able to launch VScode on their host machine and access the folder content on the VM. – Giacomo1968 Apr 03 '21 at 18:24
  • And to the original poster, [this other question](https://superuser.com/a/1407902/167207) is for macOS but otherwise seems 100% the same desire being addressed. The solution was to use sshfs to mount the directory on the VM and then working within that mounted directory. It mentions using [FUSE](https://superuser.com/q/179436/167207) for file system compatibility but that might not be needed. The overall concept is the same: Mount the directory from the VM “remotely” on your host and away you go! – Giacomo1968 Apr 03 '21 at 18:44

1 Answers1

0

A solution is described in the Microsoft article Remote Development using SSH.

This solution involves running a VScode server on the remote machine and a development VScode instance on the client machine.

The exact process is described in the article (and may change in the future). It requires installing on the server VScode the Remote Development extension pack. On the client VScode you start by selecting "Remote-SSH: Connect to Host..." from the Command Palette (F1) and using the same user@hostname from the SSH connection.

The article illustrates the process with the following diagram:

enter image description here

harrymc
  • 455,459
  • 31
  • 526
  • 924