Site icon Zit Seng's Blog

Using WSL for Remote-SSH in VS Code

I’ve been a vi user for decades, but perhaps about half a year ago, started to dabble a bit with Microsoft’s Visual Studio (VS) Code. It’s a nice editor and development environment, but there’s a bit of inelegance in working with remote development on SSH servers.

I use WSL a lot locally, and I SSH a lot from inside WSL. VS Code has nice built-in remote SSH development support, but it wants to use the Microsoft supplied OpenSSH in Windows 10. The problem with Microsoft’s OpenSSH is two-fold:

What I really want is for VS Code to simply call the ssh program inside WSL. This seems to be an oft requested feature. I hope Microsoft gets around to working this out eventually, with out-of-the-box support for WSL’s ssh. This has annoyed me enough to finally get me looking for a solution.

The issue here is to get VS Code to call a different SSH. We can’t seem to call wsl.exe ssh directly, but it seems to work if we give VS Code a batch file to call.

So here’s what to do. First, make sure that the “Remote – SSH” extension has been installed. Next, create a simple batch file ssh.bat inside, say, C:\Users\<username>\bin and put this single line in it:

C:\Windows\system32\wsl.exe ssh %*

Then, in VS Code settings, set remote.ssh.path to:

C:\Users\<username>\bin\ssh.bat

That’s it. Now you’ll have the same SSH configuration and credentials in VS Code as you have in WSL.

Update (6 May 2023): There’s an update to my VSCode SSH configuration. It’s the simpler way, and works better now.

Exit mobile version