The initial ideaearly 2017, Rich Turner made a demo where Visual Studio was used to develop C++ code, however the debugging environment targeted was WSL!
With some magic, he showed something that he had forbidden from the initial release of WSL: writting directly to the WSL filesystem (still a big no-no actually).
Of course, this triggered a lot of curiosity and the WSL Corsair had to loot from it too!
SSH to save the daythe biggest challenge was to find a way that not only could be easy to setup on both ends, and also would be approved by the WSL team.
TLDR: if you use the Windows Path, You Die! #ThereBeDragons
Another way, more Linux-oriented, needed to be used and hopefully a solution already existed and was simply waiting on being used: SSH🔐
The setupthe setup is done in 2 distinct parts:
- Setup the SSH server on WSL
- Setup the SSH client on VSCode
Still I’m glad to say that I finally found THE plugin that not only provides SSH support but also provides a more complete “developer environment experience”.
PrerequesitesBefore we start, there is 2 prerequisites that helped me a lot and I would like to share it:
- For the OpenSSH server in your WSL environment, the guides in Internet are legion, but so far the “full solution” that is working all the time for me is the answer of this post: <https://superuser.com/questions/1111591/how-can-i-ssh-into-bash-on-ubuntu-on-windows-10>
- VSCode as an integrated console which is Powershell by default. If you want to avoid going back and forth to the WSL console, you can setup the VSCode console to be your WSL shell.
- You can change your user-settings (CTRL+,) with the following line for Ubuntu flavour:
“terminal.integrated.shell.windows”: “C:\\Users\\<Your Username>\\AppData\\Local\\Microsoft\\WindowsApps\\ubuntu.exe”
ConfigurationOnce OpenSSH server is configured in WSL, the next step is to configure the VSCode plugin (of course, the help file is to read!):
- Install VSCode and/or VSCode-Insiders (this version allows you to use multi root directories in the same workspace)
- Install the plugin “FTP-Simple”
- Open the command bar (CTRL+SHIFT+P) and search for ftp-simple: config
- Create a first basic configuration just to ensure everything is working fine
- Open the command bar (CTRL+SHIFT+P) and search for ftp-simple: Remote directory to Workspace
- Choose your connection according to the name you provided in step 4
- [Optional] If you didn’t insert the password, type the password to the WSL account
- Choose from where the initial path should be open
- The workspace should be now open with the files and directories from the path you provided in step 4
Finally, let's playNow that everything is installed and configured, open a WSL terminal (in or out of VSCode depending on your setup), do some changes in your files from VSCode and see the changes being applied to your WSL files.
Last (random) comments
- This solution does not work with a separated terminal opened. The Workspace of VSCode keeps the SFTP connection alive, that’s what allow us to directly modify the files without having a new VSCode window being open
- Your initial directory is the new ‘/’. You can think of it as a ‘chroot’. This means that if you try to open a file that is ‘below’ your initial directory, it will not work
- Microsoft is working hard on bringing full interopability between WSL and Windows applications (filesystem included). So consider this post to be obsolete in the (near?) future.
- The SSH solution is not my idea and it’s just an adaptation of Microsoft own solution for C++ and WSL <https://blogs.msdn.microsoft.com/vcblog/2017/02/08/targeting-windows-subsystem-for-linux-from-visual-studio/>.
>>> Nunix Out <<<