Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remote-SSH: Fails to discover WSL SSH #937

Open
Tracked by #9044
UnicodeTreason opened this issue Jul 9, 2019 · 105 comments
Open
Tracked by #9044

Remote-SSH: Fails to discover WSL SSH #937

UnicodeTreason opened this issue Jul 9, 2019 · 105 comments
Assignees
Labels
feature-request Request for new features or functionality plan-review PM-highlighted item determined to be P1 or P2 ssh Issue in vscode-remote SSH
Milestone

Comments

@UnicodeTreason
Copy link

  • VSCode Version: 1.37.0-insider
  • Local OS Version: Windows 10 1803
  • Remote OS Version: N/A
  • Remote Extension/Connection Type: SSH

Steps to Reproduce:

  1. Have Remote-SSH installed
  2. Connect to Host
  3. VSCode fails to find any SSH with error "An SSH installation couldn't be found"
  4. I checked the Remote - SSH Output and can't even see it attempting to look for WSL SSH
    Got error from ssh: spawn ssh ENOENT
    Testing ssh with C:\WINDOWS\System32\OpenSSH\ssh.exe -V
    Got error from ssh: spawn C:\WINDOWS\System32\OpenSSH\ssh.exe ENOENT
    Testing ssh with C:\Program Files\Git\usr\bin\ssh.exe -V
    Got error from ssh: spawn C:\Program Files\Git\usr\bin\ssh.exe ENOENT
    Testing ssh with C:\Program Files (x86)\Git\usr\bin\ssh.exe -V
    Got error from ssh: spawn C:\Program Files (x86)\Git\usr\bin\ssh.exe ENOENT
    Finding installed ssh failed: ssh installation not found
    ssh installation not found

Which is unexpected as the documentation here: https://code.visualstudio.com/docs/remote/troubleshooting#_installing-a-supported-ssh-client

Specifically states it'll use WSL SSH
image

These closed issues also make it look as though it WAS added recently:
#359
#448

@Chuxel
Copy link
Member

Chuxel commented Jul 12, 2019

@roblourens Did the update to dynamically find the SSH client on Windows include a WSL check or did that get cut/missed?

@roblourens
Copy link
Member

Yeah I missed that entirely. Can you suggest how I should discover/invoke WSL ssh?

Also would have to figure out how config files will work. WSL ssh would not look at windows' ssh config files by default and vice versa.

@roblourens roblourens self-assigned this Jul 13, 2019
@roblourens roblourens added feature-request Request for new features or functionality ssh Issue in vscode-remote SSH labels Jul 13, 2019
@davidwin
Copy link

Enabling the WSL ssh would be awesome, since it should make it possible to take advantage of ControlMaster on Windows. We rely on WSL ssh heavily for a homegrown remote development solution, and connection multiplexing really helps to make things zippy.

@Chuxel
Copy link
Member

Chuxel commented Jul 18, 2019

@roblourens I've got a PR out to update docs in the mean time.

You should be able to detect WSL SSH with the following command line call:

where wsl && wsl which ssh

Non-zero exit means it's not there.

@roblourens roblourens added this to the July 2019 milestone Jul 19, 2019
@UnicodeTreason
Copy link
Author

Thanks for jumping onto this one guys, saves us having to run two SSH configurations.

@diablodale
Copy link

diablodale commented Jul 24, 2019

Additional test case as this is implemented...

  • Force usage of WSL ssh

I tried three alternate settings.json of

  "remote.SSH.path": "C:\\Windows\\System32\\wsl.exe ssh"
  "remote.SSH.path": "\\\\wsl$\\Ubuntu-18.04\\usr\\bin\\ssh"
  "remote.SSH.path": "/usr/bin/ssh"

They all failed with the Remote - SSH output log reporting for each their location...

Testing ssh with C:\Windows\System32\wsl.exe ssh -V
Got error from ssh: spawn C:\Windows\System32\wsl.exe ssh ENOENT
The specified path C:\Windows\System32\wsl.exe ssh is not a valid SSH binary

I have a very little tested workaround to force WSL ssh. Use a settings.json of

  "remote.SSH.path": "c:/njs/ssh.bat"

with an ssh.bat of

@echo off
set v_params=%*
set v_params=%v_params:\=/%
set v_params=%v_params:c:=/mnt/c%
REM set v_params=%v_params:"=\"%
C:\Windows\system32\wsl.exe ssh %v_params%

@diablodale
Copy link

Hello. A regression in use of the setting remote.SSH.path to use WSL occurred in VSCode Windows release 1.37.0; where no problem existed in the previous 1.36.x. Putting it in this issue as it is highly related to this discussion.

The setting remote.SSH.path no longer accepts correctly a path like c:/njs/ssh.bat
In 1.37 on Windows, the setting must be with backslashes.

Setup

Version: 1.37.0 (system setup)
Commit: 036a6b1d3ac84e5ca96a17a44e63a87971f8fcc8
Date: 2019-08-08T02:33:50.993Z
Electron: 4.2.7
Chrome: 69.0.3497.128
Node.js: 10.11.0
V8: 6.9.427.31-electron.0
OS: Windows_NT x64 10.0.18362

Repo

  1. Setup the ssh.bat file in a directory, and VSCode remote.SSH.path as in Remote-SSH: Fails to discover WSL SSH #937 (comment)
  2. Run and connect using Remote SSH

Result

The connection fails. In the Remote SSH output window is the error

[10:35:33.341] Install and start server if needed
[10:35:33.404] > 
[10:35:33.405] Got some output, clearing connection timeout
[10:35:33.903] > �]0;C:\WINDOWS\SYSTEM32\cmd.exe�
[10:35:33.912] >
...
[10:35:33.920] > 'c:' is not recognized as an internal or external command,
> operable program or batch file.

Expected

No error and a successful connection

Workaround

Change the setting of the path to use backslashes

"remote.SSH.path": "c:/njs/ssh.bat"    <--- fails
"remote.SSH.path": "C:\\njs\\ssh.bat"    <--- works

@roblourens
Copy link
Member

Ugh windows. Forked that into #1148, thanks.

@andrzejnovak
Copy link

I can attest that using ssh through wsl would be amazing. Apart from the obvious non-duplication of configs, I need to connect to a host which only allows kerberos authentication.

Is there a documented workaround for now? I tried the ssh.bat file hack mentioned above, but got nowhere. There's an error stating The specified path is not a valid SSH binary

@8549
Copy link

8549 commented Nov 11, 2019

Setting remote.ssh.path to \\wsl$\Ubuntu-18.04\usr\bin\ssh doesn't work, either.

@UnicodeTreason
Copy link
Author

Seems like this one's a doozy, everyone's efforts are appreciated.

@PathosV
Copy link

PathosV commented May 25, 2023

My previous solution to this broke today.

I had to change

C:\Windows\system32\wsl.exe -e bash -ic "ssh -Y %v_params%"

to

C:\Windows\system32\wsl.exe bash -ic "ssh -Y %v_params%"

otherwise I would get the error:

Shell "bash" is not executable: No such file or directory

Playing around in PowerShell, it looks like a change in how WSL launches commands.

The other annoying change is that VSCode is not populating the hosts list from my WSL .ssh/config. By default it grabs the copy I have in C:\Users....ssh, if I hard code the WSL path as I've done in the past, the list is blank. Removing the windows copy does not force it to look for the WSL copy. With the config path blank, and the list populated by the windows config file, I can launch remote connections with no issues, BUT, it's using the settings from the WSL config file!

@hbthegreat
Copy link

hbthegreat commented Jul 28, 2023

For those coming now to this I tried a lot of the solutions above the one that worked was the ssh.bat approach:

Make the file

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

Change your settings.json to include:

"remote.SSH.path": "C:/<yourfolderhere>/ssh.bat"

Everything then works through the config in your wsls ssh config.

@JtMotoX
Copy link

JtMotoX commented Aug 18, 2023

For those suddenly having issues with vsc no longer loading the wsl ssh config file. Beginning with VS Code 1.78.1, accessing any UNC path (those that begin with \\) is blocked to mitigate a security risk that is covered in this Security Advisory.

This can be fixed by adding the following to your settings.json and then restarting vsc.

"security.allowedUNCHosts": ["wsl$", "wsl.localhost"],

@sXe79
Copy link

sXe79 commented Aug 22, 2023

This can be fixed by adding the following to your settings.json and then restarting vsc.

"security.allowedUNCHosts": ["wsl$"],

In my case I had to add "wsl.localhost" instead of "wsl$"

Thanks!

@JtMotoX
Copy link

JtMotoX commented Aug 22, 2023

In my case I had to add "wsl.localhost" instead of "wsl$"

Ahh good point @sXe79. Yes, 'wsl.localhost' is sometimes used instead of 'wsl$'. I have updated my comment to include that.

@Darkzarich
Copy link

Darkzarich commented Sep 1, 2023

Still doesn't work to this day, tried everything

Update on my problem. As of 09.01.23, ver. 1.81.1 everything works just fine if I leave remote.SSH.path just empty but before that I needed to add wsl$ to security.allowedUNCHosts - without that my list of available SSH hosts was empty

@einarpersson
Copy link

einarpersson commented Sep 24, 2023

I really cannot get this to work. I just want to connect from my WSL2 instance to my home server using my WSL2 ssh and config file

Version: 1.82.2 (user setup)
Commit: abd2f3db4bdb28f9e95536dfa84d8479f1eb312d
Date: 2023-09-14T05:55:25.390Z
Electron: 25.8.1
ElectronBuildId: 23779380
Chromium: 114.0.5735.289
Node.js: 18.15.0
V8: 11.4.183.29-electron.0
OS: Windows_NT x64 10.0.19044

What should I paste into settings.json to get this to work? Do I need a bat-script or not?


EDIT

"security.allowedUNCHosts": ["wsl$"],
  "remote.SSH.path": "\\\\wsl$\\Ubuntu\\usr\\bin\\ssh",
  "remote.SSH.configFile": "\\\\wsl$\\Ubuntu\\home\\einar\\.ssh\\config",
  "remote.SSH.showLoginTerminal": true,

With this VSCode detects the config file, since I can see hosts that I have added to the config file. However, the usage of the config file fails since it looks for the identity file relative to the windows file system (I see this briefly in an error which disappears quickly)

@ltalirz
Copy link

ltalirz commented Sep 24, 2023

this approach still works fine #937 (comment)

@einarpersson
Copy link

einarpersson commented Sep 24, 2023

this approach still works fine #937 (comment)

So what is the value of remote.SSH.configFile?

I have tried this now and leaving it unset does not work for me. Neither does setting it to ~/.ssh/config or "\\\\wsl$\\Ubuntu\\home\\einar\\.ssh\\config".

Please share a settings.json example if you've gotten it to work! 😄 🙏

EDIT
Forget about it, now it started working. (i.e. not setting remote.SSH.configFile)

Thanks!

(would be great with official support though...)

@protection6 protection6 mentioned this issue Sep 29, 2023
@awyuan
Copy link

awyuan commented Oct 12, 2023

I'm having this issue again in 1.83.1. I use the solution from #937 and it worked fine in the past but now does not. I have tried the allowedUNCHosts but remote-ssh does not find wsl

@sudo-bussmann
Copy link

I'm been having this issue persist since maybe July. I've tried most of the fixes in the thread but nothing seems to fix the ability to actually use the SSH config file. The "security.allowedUNCHosts" showed promise and VSC was able to show my SSH config from WSL but still was not able to actually use the WSL ssh binary without throwing an error.

@ltalirz
Copy link

ltalirz commented Nov 6, 2023

I'm having this issue again in 1.83.1. I use the solution from #937 and it worked fine in the past but now does not. I have tried the allowedUNCHosts but remote-ssh does not find wsl

If the error in the console is /bin/sh: ssh: not found, you may want to try #937 (comment)

@andrzejnovak
Copy link

I've found that the prescription in #937 (comment) still works. However, I have a wrapper (passing appropriate bitwarden password) of the ssh binary which requires user input to proceed and the WSL terminal window won't any user input, is there a way around it? Strangely enough Ctrl+C does register in the terminal, but typing in y/n does not.

@likair
Copy link

likair commented Nov 23, 2023

This configuration works for me (Version: 1.84.2)

"remote.SSH.configFile": "\\\\wsl.localhost\\Ubuntu\\home\\$USER\\.ssh\\config",
"security.allowedUNCHosts": ["wsl$", "wsl.localhost"]

@jdratlif
Copy link

jdratlif commented Apr 6, 2024

I have tried several times over the past couple years to get this to work always hoping it will, and always being disappointed. I'm amazed that so many of you find it to be functional.

I tried adding the bat file in my home directory that runs wsl ssh.exe %*. When I try to login, it asks me for a password. It may or may not accept the input. If it asks me ANY follow up questions (accept this key?), it will DEFINITELY not accept that input. I tried adding "remote.SSH.showLoginTerminal": true, but I can't type in there either.

If I use controlmaster (which is the whole point) and connect to my server first from wsl, I get a new error about "dynamic port forwarding fails". The command ran, and it looks good to me. I use curl as a socks proxy with the dynamic port it opened and it's working JUST fine. So is VScode looking for the port on the local windows host? That wouldn't work, but that would explain why it clearly set things up, but nothing works.

Do none of you experience these problems? I don't think I'm doing anything unusual here. I want ControlMaster and ProxyJump because my work requires a bastion host.

@UnicodeTreason
Copy link
Author

I just install "Git for Windows" and wait for the day the devs work out this feature and I can stop installing it.

@devd79
Copy link

devd79 commented Apr 8, 2024

@UnicodeTreason Can you share your setting.?

I have tried several times over the past couple years to get this to work always hoping it will, and always being disappointed. I'm amazed that so many of you find it to be functional.

I tried adding the bat file in my home directory that runs wsl ssh.exe %*. When I try to login, it asks me for a password. It may or may not accept the input. If it asks me ANY follow up questions (accept this key?), it will DEFINITELY not accept that input. I tried adding "remote.SSH.showLoginTerminal": true, but I can't type in there either.

If I use controlmaster (which is the whole point) and connect to my server first from wsl, I get a new error about "dynamic port forwarding fails". The command ran, and it looks good to me. I use curl as a socks proxy with the dynamic port it opened and it's working JUST fine. So is VScode looking for the port on the local windows host? That wouldn't work, but that would explain why it clearly set things up, but nothing works.

Do none of you experience these problems? I don't think I'm doing anything unusual here. I want ControlMaster and ProxyJump because my work requires a bastion host.

same here..gave up! ;(

@Raibows
Copy link

Raibows commented Apr 9, 2024

@devd79 @UnicodeTreason

Same here. After so many times trying and always being disappointed when dealing with complex ssh configs like proxyjump or remote command, I find the best way for it is to use vscode in WSL GUI.

@UnicodeTreason
Copy link
Author

@devd79 No special settings, VSCode just uses the SSH that "Git for Windows" installs according to the doc.

Though I just checked and it seems my VSCode is now using the SSH that PowerShell uses (No idea if its vanilla or my desktop SOE team are legens). Guess I swapped to using it a while back and forgot about it.

[15:11:38.761] Checking ssh with "C:\WINDOWS\system32\ssh.exe -V"
[15:11:38.766] Got error from ssh: spawn C:\WINDOWS\system32\ssh.exe ENOENT
[15:11:38.767] Checking ssh with "C:\WINDOWS\ssh.exe -V"
[15:11:38.768] Got error from ssh: spawn C:\WINDOWS\ssh.exe ENOENT
[15:11:38.769] Checking ssh with "C:\WINDOWS\System32\Wbem\ssh.exe -V"
[15:11:38.770] Got error from ssh: spawn C:\WINDOWS\System32\Wbem\ssh.exe ENOENT
[15:11:38.770] Checking ssh with "C:\WINDOWS\System32\WindowsPowerShell\v1.0\ssh.exe -V"
[15:11:38.772] Got error from ssh: spawn C:\WINDOWS\System32\WindowsPowerShell\v1.0\ssh.exe ENOENT
[15:11:38.772] Checking ssh with "C:\WINDOWS\System32\OpenSSH\ssh.exe -V"
[15:11:38.823] > OpenSSH_for_Window
[15:11:38.823] > s_8.1p1, LibreSSL 3.0.2

The REAL pain is having more than one .ssh dir floating around.
I have a script that syncs my WSL .ssh into C:\Users\USERNAME.ssh every day.

@jdratlif
Copy link

@Raibows I didn't notice your response, but I came to the same conclusion today -- running the linux version from WSLg. Spent some time testing and it seems to work perfectly. I even got usbipd working so I can pass thru my smart card reader and connect to the jump hosts that need that.

@mahmoud-samy
Copy link

Update 2024-04-22:

  1. Create a batch file: In your file explorer, navigate to C:\Users\[USER] and create a file named wsl-ssh.bat. Inside the file, add the following line:

    C:\Windows\system32\wsl.exe ssh %*
  2. Link SSH folders: In the Command Prompt (run as Administrator), execute the following command to create a symbolic link between your WSL and Windows SSH folders:

    mklink /d C:\Users\[USER]\.ssh \\wsl.localhost\Ubuntu\home\[USER]\.ssh

@jdratlif
Copy link

@mahmoud-samy I don't know why you posted this. It's almost exactly what's already been posted in this thread, except you left out some important stuff like setting VS Code to use that batch file for the ssh path, and the most important detail, that THIS DOES NOT WORK.

I would love to be proven wrong, btw. I would love to see a video demonstrating the entire process from start to finish. Create the batch file, set up VS code remote SSH path, open a connection to a remote SSH server, and open a workspace on that remote server from the terminal.

I've been trying on and off for at least 2 years to get WSL SSH to work with Windows VS Code, and it's never worked even once. The batch file idea LOOKS promising. It did connect to a remote server for me ONE time, but I couldn't open a workspace afterwards, so even that was useless. It never would connect to the server again -- no idea why it worked the first time.

After using the wslg Linux version for a couple weeks, I find it works pretty well, though wslg seems to crash sometimes with my windows freezing up and being totally unresponsive. I have to use wsl.exe --shutdown and restart things. But it hasn't happened often enough to get me to abandon it, but if I could get WSL ssh working with VS code windows, I would totally do that.

TLDR; Microsoft is never going to fix this. Whatever reason any of us have for wanting to use WSL ssh is not important enough to dedicate developer resources towards. wslg is a realistic (if imperfect) solution. If you need a fully functional OpenSSH client, don't use Windows.

@burple-ml
Copy link

burple-ml commented Jul 25, 2024

I have been able to use @ltalirz 's teknik here: #937 (comment)
which is very simple and effective. I will though note the following:-

  • that I had to change my .bat files encoding to use ANSI or UTF-8 because my machine was defaulting to UTF-16. I am not sure if others have mentioned this problem, or unaware of this possible cause of failure,but it was what was stopping me in the first place.

  • also, if you are not messing arround much with your aliases in your bash profile, then you should consider just typing wsl ssh %* in your .bat file which is like a symlink between the 2 os'es.

  • also if you are using @ltalirz's method then please do not use the networkpath \\wsl.localhost\ubuntu\home \foo\bar\alice\config in the remote.ssh.config field, as windows basically passes it to the .bat file as an argument, which in our case is sent to a linux cli application (namely the default ssh aplication on your wsl), and then vscode will see that it all fails, so it just defaults to using the system default ssh application etc.etc.

having said that my setup is not a 100 percent on UX or simply said is not fully refined as a few screws need tightening up, and this could be the fourth point for observation to the above,

  • sometimes you might face an error where vscode is not able fulfill all auto forwarding's, so that needs to be disabled from the get go.

FUTURE WORK:-

  • there seems to be some promise with the setting called "remote.extensionKind" setting, which you can put in the settings.json, and specify whether the extension can be installed on the local machine or on the remote machine, i.e, we can now instruct vscode to install the extension on the remote machine, and not do the hybrid where ui is setup remotely, and extension is run locally.

tested on : vscode 1.89.1 on my windows 11 machine, where I am running wsl ubuntu-22-04.

@bebrooke
Copy link

I was struggling with the ssh.bat method, and kept getting prompted for the (wsl) ssh key passphrase until I realised it was using the default bash shell even after I used chsh to set my shell to zsh. Updating ssh.bat to the following fixed it for me :

C:\Windows\system32\wsl.exe -e zsh -li -c "ssh %*"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Request for new features or functionality plan-review PM-highlighted item determined to be P1 or P2 ssh Issue in vscode-remote SSH
Projects
None yet
Development

No branches or pull requests