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:
- It keeps its own set of configuration and keys in
%USERPROFILE%\.ssh\. This is kind of inconvenient when you use SSH inside WSL a lot. I know I could sync the two environments, but it’s just inelegant I just want one copy of my SSH setup.
- A bigger problem is that Microsoft’s OpenSSH doesn’t provide support for ProxyJump, a feature I use a lot. This is a convenient feature for tunnelling connections through jump hosts. Again, there are workarounds using ProxyCommand, but I find them inelegant.
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
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.
17 thoughts on “Using WSL for Remote-SSH in VS Code”
I get “Finding installed ssh failed: spawn UNKNOWN”
This worked nicely for me!!! Thank you very much.
I just only had to enable also the ssh agent in the wsl Ubuntu OS, because I am using a passphrase protected key for ssh authentication.
Thanks, great tip! Now I have a single config for Win and WSL 🙂
Hey its not working anymore. Can’t get it to work on Windows 10 or 11.
Can’t seem to find a reason. It’s just not using the bat file
I’m still using it, seems to work fine for me.
Hi, using Windows 10 with a clean install of VS Code. I added the files like in the instructions and it doesn’t bring up any of my existing hosts. Are you on the latest VS code?
Yes I just checked, latest version, works fine. I’m not sure what you mean by “bring up any of my existing hosts”. You need to specify them when you SSH. The list of host doesn’t just appear for you. My main purpose is to make sure that both VSCode and WSL2 share the same SSH configuration, so that anything I configure (including keys, etc) only need to be done once and will be used identically in both WSL2 and VSCode.
Change Remote.SSH:Config File to \\wsl$\Ubuntu\root\.ssh\config
Then, all your hosts will appear on the ssh targets bar
Have been trying for a while to make this work. I find similar issues to previous recent users, the use of the bat file returns the following error:
Checking ssh with “C:\Users\\bin\ssh.bat -V”
Got error from ssh: spawn C:\Users\\bin\ssh.bat ENOENT
The specified path C:\Users\\bin\ssh.bat is not a valid SSH binary
Any help would be extremely appreciated.
I’m not sure if some text is missing due to special chars, but make sure your path is indeed correct. E.g. mine would be something like C:\Users\lzs\bin\ssh.bat.
For me, it didn’t pick up any configuration from the ssh config file within WSL. So I just added the path to that file too.
I am frequently running into this issue recently,
0 [main] ssh 1629 D:\tool\Git\usr\bin\ssh.exe: *** fatal error – console device allocation failure – too many consoles in use, max consoles is 32
2717 [main] ssh 1629 cygwin_exception::open_stackdumpfile: Dumping stack trace to ssh.exe.stackdump
so I have to manually kill the process tree and restars VSCode, which was very annoying.
Now I am able to work around it by using your solution!
Thanks a lot!
`wsl.exe ssh %*` does not help to resolve the `console device allocation failure – too many consoles in use, max consoles is 32` problem, but it provides the benefit that Windows and WSL can share the ssh config so no need to maintain a copy in Windows, as the author mentioned.
Hi Zit Seng,
Thank you very much for the post. I followed your steps to (1) set remote.ssh.path the ssh.bat file and (2) add wsl ssh %* to the ssh.bat file.
I can verify that from cmd, I can run the ssh.bat file to log on to a remote host and that the ssh is using the .config file of the wsl installation.
When I run the remote connect to the remote host, it got stuck at the password prompt step in that when I enter my password, there is no response at all, even though I can still notice the blinking curser at the password prompt location.
Any ideas how to fix this problem?
Thanks in advance!
You should probably just setup SSH keys for automatic login. I don’t think the remote-ssh plugin was meant to support manual password input (though I could be mistaken).
how do u do this? I’m having the same issue
View Comment Policy