Open UnicodeTreason opened 5 years ago
@roblourens Did the update to dynamically find the SSH client on Windows include a WSL check or did that get cut/missed?
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.
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.
@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.
Thanks for jumping onto this one guys, saves us having to run two SSH configurations.
Additional test case as this is implemented...
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%
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.
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
remote.SSH.path
as in https://github.com/microsoft/vscode-remote-release/issues/937#issuecomment-514714615The 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.
No error and a successful connection
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
Ugh windows. Forked that into https://github.com/microsoft/vscode-remote-release/issues/1148, thanks.
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
Setting remote.ssh.path
to \\wsl$\Ubuntu-18.04\usr\bin\ssh
doesn't work, either.
Seems like this one's a doozy, everyone's efforts are appreciated.
The script provided by @diablodale doesn't seem to work for me. When I go through the dialog to create a new remote SSH connection, it prompts me for the command and then the config file (of which I use a path to the WSL one) and then nothing happens. No new window opens up and no connection is added.
@sweepyoface , contact me via email if you want my help diagnosing. It is a workaround, and I prefer not to muddy this issue w/ support convo on a workaround. :-)
@diablodale actually if you could that would be great, this clearly collected a bunch of ppl who'd like a fix but it doesn't work, presumably many more didn't bother to comment
Install/Discussion for my BAT workaround is at https://gist.github.com/diablodale/54756043c395d712053cf0d50a86086a
Can confirm @diablodale 's shim works great. Presumably it something that could be added natively to the extensions?
Can also confirm @diablodale 's shim works great. Just wanted to additionally report that it doesn't play nice with Use Local Server, which might be a separate issue from this.
Change the last line of @diablodale 's script to:
C:\Windows\system32\bash.exe -ic "%~n0 %v_params%"
Your ssh-agent will now work! This just loads your profile so the env vars are set.
That works great @lancslingwood!
I made a couple more changes to be able to use the same ssh config between vscode and WSL2, so here's the full instructions I've followed so far on Windows 10 v2004 if it's helpful to anyone:
Use @diablodale's shim, saved to C:\Users\Clive\ssh.BAT
(home directory is in the Windows PATH by default, and for me it gets called first ahead of my OpenSSH installation)
With the last line of that file modified so it grabs the env variables and can use the ssh-agent (@lancslingwood):
C:\Windows\system32\bash.exe -ic "%~n0 %v_params%"
vscode config (if you saved ssh.BAT somewhere else, you need to set remote.SSH.path
as well.) Make sure to set your User config, not your Remote or Workspace configs.
"remote.SSH.configFile": "\\\\wsl$\\Ubuntu\\home\\clive\\.ssh\\config"
Make sure bash knows what to do with the config file path when vscode passes it with ssh -F
:
sudo ln -s / //wsl$/Ubuntu
All this feels like a massive Frankenstein but at least it's an invisibly scripted Frankenstein now :P
If your specific setup needs to run .profile
and/or .bashrc
there are several combinations of bash features which cause those files to load but also creates side-affects. Your specific setup/needs can guide you on this. ð
https://www.gnu.org/software/bash/manual/html_node/Bash-Startup-Files.html
-i
indicates an interactive shell and additional code/features happen when bash is marked interactive. One example: the default .bashrc
has code near # If not running interactively
which prevents running most of that file. If you want the fastest execution of the shim's command with a more "pure" non-interactive session, it is usually not appropriate to indicate it is interactive. I use the shim for many things that need fast execution, e.g. pylint
, so I do not use the -i
approach.
Instead, I use the approach as written in the shim using wsl.exe
and use the bash environment variable BASH_ENV=~/.bashrc
. I set that variable as a Windows user environment variable and WSLENV=BASH_ENV
so it is passed to the WSL subsystem. Now when I run something with wsl.exe
it is non-interactive non-login yet runs ~/.bashrc
. I discovered in some circumstances of truly interactive and/or login sessions, the .bashrc
will then load twice. I stopped that by putting an if
test at the top of .bashrc
to catch those circumstances. ðĪŠ
- Make sure bash knows what to do with the config file path when vscode passes it with
ssh -F
:sudo ln -s / //wsl$/Ubuntu
Heads up, I had to first
sudo mkdir //wsl$
to get this to work.
These solutions don't work for me.
Here're my settings and codes. Can anyone fix?
wsl2 version
$ wslsys
Release Install Date: 0x5ed27425
Branch: vb_release
Build: 19041
Full Build: 19041.1.amd64fre.vb_release.191206-1406
Uptime: 0d 0h 14m
Linux Release: Ubuntu 20.04 LTS
Linux Kernel: Linux 4.19.104-microsoft-standard
Packages Count: 1127
C:\Users\monad\Codes\ssh.BAT (I've confirmed this has 0 byte output.)
SETLOCAL EnableExtensions
SETLOCAL DisableDelayedExpansion
set v_params=%*
set v_params=%v_params:\=/%
set v_params=%v_params:c:=/mnt/c%
REM set v_params=%v_params:"=\"%
REM C:\Windows\system32\wsl.exe %~n0 %v_params%
C:\Windows\system32\bash.exe -ic %~n0 %v_params%
The reason I changed wsl.exe
into bash.exe -ic
is my default shell is fish, which has over 0 byte output when executing true.BAT
.
settings.json of VSCode
"remote.SSH.path": "C:\\Users\\monad\\Codes\\ssh.BAT",
"remote.SSH.configFile": "\\\\wsl$\\Ubuntu\\home\\monado\\.ssh\\config",
at Ubuntu
$ la /wsl\$/
total 8.0K
drwxr-xr-x 2 root root 4.0K Jun 5 00:49 ./
drwxr-xr-x 20 root root 4.0K Jun 5 11:59 ../
lrwxrwxrwx 1 root root 1 Jun 5 00:49 Ubuntu -> //
the output when I executed remote-ssh
[12:08:49.089] Log Level: 2
[12:08:49.092] remote-ssh@0.51.0
[12:08:49.092] win32 x64
[12:08:49.094] SSH Resolver called for "ssh-remote+kugenuma", attempt 1
[12:08:49.095] SSH Resolver called for host: kugenuma
[12:08:49.095] Setting up SSH remote "kugenuma"
[12:08:49.114] Using commit id "5763d909d5f12fe19f215cbfdd29a91c0fa9208a" and quality "stable" for server
[12:08:49.115] Install and start server if needed
[12:08:51.068] Checking ssh with "C:\Users\monad\Codes\ssh.BAT -V"
[12:08:51.252] ssh exited with code: 255
[12:08:51.253] The specified path C:\Users\monad\Codes\ssh.BAT is not a valid SSH binary
[12:08:51.253] Checking ssh with "ssh -V"
[12:08:51.255] Got error from ssh: spawn ssh ENOENT
[12:08:51.255] Checking ssh with "C:\WINDOWS\System32\OpenSSH\ssh.exe -V"
[12:08:51.288] > OpenSSH_for_Windows_7.7p1, LibreSSL 2.6.5
[12:08:51.299] Using SSH config file "\\wsl$\Ubuntu\home\monado\.ssh\config"
[12:08:51.299] Running script with connection command: "C:\WINDOWS\System32\OpenSSH\ssh.exe" -T -D 50953 -F "\\wsl$\Ubuntu\home\monado\.ssh\config" kugenuma bash
[12:08:51.302] Terminal shell path: C:\WINDOWS\System32\cmd.exe
[12:08:51.394] > CreateProcessW failed error:2
> ]0;C:\WINDOWS\System32\cmd.exe
[12:08:51.394] Got some output, clearing connection timeout
[12:08:51.412] > posix_spawn: No such file or directory
> The process tried to write to a nonexistent pipe.
[12:08:51.854] "install" terminal command done
[12:08:51.855] Install terminal quit with output: The process tried to write to a nonexistent pipe.
[12:08:51.855] Received install output: The process tried to write to a nonexistent pipe.
[12:08:51.857] Resolver error: The process tried to write to a nonexistent pipe
[12:08:51.868] ------
Well, my setup WAS working with the ssh.BAT shim. However it stopped working a couple days ago & I'm getting a similar error to @monado3 .
Checking ssh with "C:\\scripts\\ssh.BAT -V"
ssh exited with code: 1
The specified path C:\\scripts\\ssh.BAT is not a valid SSH binary
Running C:\\scripts\\ssh.BAT -V
in cmd returns OpenSSH_8.2p1 Ubuntu-4ubuntu0.1, OpenSSL 1.1.1f 31 Mar 2020
& I am able to use ssh.BAT to open ssh in wsl FROM cmd. So I know that the shim works. But remote-ssh's check if it's a valid binary is stopping it from even getting a chance to run...
@roblourens Any progress on this to report? I assume WSL 2 might shake things up a little.
Look below âââ https://github.com/microsoft/vscode-remote-release/issues/937#issuecomment-755440954
I used my poor knowledge of C language to write a program, according to your own needs to compile it into
ssh.exe
. Hope there are other awesome people can help me optimize, I'm just a novice.Because this program just forwards ssh.exe
's parameters to WSL or other bash environment. So, you can fully use the configuration used in WSL or other bash environments before. For example, the key file uses the internal location of WSL rather than the absolute location of key file in Windows environment.
#include <stdlib.h>
#include <string.h>
int main(int argc, char *argv[]) {
int count;
char ch[100] = "bash.exe -c \"ssh";
for (count = 1; count < argc; ++count) {
char ch0[100] = " ";
strcat_s(ch0, sizeof(ch0), argv[count]);
strcat_s(ch, sizeof(ch), ch0);
}
strcat_s(ch, sizeof(ch), "\"");
system(ch);
return 0;
}
@fxzxmic's program is working for me!
Note that if you're compiling it on WSL/WSL 2, you need to use a windows compiler like mingw.
Steps I used to get it working:
1: Install a windows C/C++ compiler:
sudo apt-get install mingw-w64
2: Save @fxzxmic's code as ssh.c
3: Compile into a windows exectutable:
x86_64-w64-mingw32-g++ -o ssh.exe ssh.c
4: Set the path to ssh.exe in the remote-ssh settings:
C:\\some\\path\\ssh.exe
I had the same issue, I don't know why this showed up. But it has been fixed when I restart the system :)
I have a better program to do this. https://github.com/fxzxmic/CMD_to_Bash
@roblourens Anything we as the community can do to help get this one out of the backlog/resolved?
I'm also having some trouble here, hopefully it can help debug or move things along from the production side.
I've essentially followed the steps outlined in this very helpful comment, and I succeed on one machine running WSL 1, and fail on another machine running WSL 2. I can't see any other relevant difference than WSL version.
(My $0.02: this clearly seems to be a feature with demand from the community side. I'd vote for prioritizing its development so it may be available "out-of-the-box," rather than relying on workarounds which tend to break :) )
Key steps:
ssh.BAT
in Windows, with the following contents (at least):
C:\Windows\system32\wsl.exe ssh %*
sudo ln -s / //wsl$/Ubuntu
"remote.SSH.path": "\\path\\to\\ssh.BAT",
"remote.SSH.configFile": "//wsl$/Ubuntu/home/zatkins/.ssh/config"
If I do this, my "SSH targets" appropriately populate in VSCode (VSCode can read my ssh config), and, as others have noted, I can ssh using my ssh.BAT
file from within CMD (in principle, everything works). On my WSL 1 machine, connecting to an SSH target works fine. On my WSL 2 machine, connecting seems to hang after the password prompt:
[14:34:48.580] Log Level: 2
[14:34:48.592] remote-ssh@0.65.4
[14:34:48.592] win32 x64
[14:34:48.593] SSH Resolver called for "ssh-remote+daq", attempt 1
[14:34:48.594] "remote.SSH.useLocalServer": false
[14:34:48.594] "remote.SSH.showLoginTerminal": false
[14:34:48.594] "remote.SSH.remotePlatform": {"daq":"linux"}
[14:34:48.594] "remote.SSH.path": D:\ssh.BAT
[14:34:48.594] "remote.SSH.configFile": //wsl$/Ubuntu/home/zatkins/.ssh/config
[14:34:48.594] "remote.SSH.useFlock": true
[14:34:48.595] "remote.SSH.lockfilesInTmp": false
[14:34:48.595] "remote.SSH.localServerDownload": auto
[14:34:48.595] "remote.SSH.remoteServerListenOnSocket": false
[14:34:48.595] "remote.SSH.showLoginTerminal": false
[14:34:48.595] "remote.SSH.defaultExtensions": []
[14:34:48.595] "remote.SSH.loglevel": 2
[14:34:48.595] SSH Resolver called for host: daq
[14:34:48.595] Setting up SSH remote "daq"
[14:34:48.620] Using commit id "054a9295330880ed74ceaedda236253b4f39a335" and quality "stable" for server
[14:34:48.623] Install and start server if needed
[14:34:48.648] Checking ssh with "D:\ssh.BAT -V"
[14:34:48.704] stdout>
C:\Users\zatki\AppData\Local\Programs\Microsoft VS Code>C:\Windows\system32\wsl.exe ssh -V
[14:34:48.752] > OpenSSH_8.2p1 Ubuntu-4ubuntu0.1, OpenSSL 1.1.1f 31 Mar 2020
[14:34:48.847] Using SSH config file "//wsl$/Ubuntu/home/zatkins/.ssh/config"
[14:34:48.847] Running script with connection command: "D:\ssh.BAT" -T -D 62299 -F "//wsl$/Ubuntu/home/zatkins/.ssh/config" daq bash
[14:34:48.851] Terminal shell path: C:\Windows\System32\cmd.exe
[14:34:49.070] > ]0;C:\Windows\System32\cmd.exe
[14:34:49.070] Got some output, clearing connection timeout
[14:34:49.091] > C:\Users\zatki>C:\Windows\system32\wsl.exe ssh -T -D 62299 -F "//wsl$/Ubuntu/hom
> e/zatkins/.ssh/config" daq bash
[14:34:49.506] > zatkins@xyz's password:
[14:34:49.506] Showing password prompt
[14:34:53.603] Got password response
[14:34:53.604] "install" wrote data to terminal: "*************"
[14:34:56.245] >
> C:\Users\zatki>C:\Windows\system32\wsl.exe ssh -T -D 62299 -F "//wsl$/Ubuntu/home/zatkins/.ssh/config" daq bash
> zatkins@xyz's password:
>
>
>
>
>
>
>
>
>
>
[14:34:56.246] Showing password prompt
[14:35:04.044] Password dialog canceled
[14:35:04.045] "install" terminal command canceled
[14:35:04.046] Resolver error: Error: Connecting was canceled
at Function.Canceled (c:\Users\zatki\.vscode\extensions\ms-vscode-remote.remote-ssh-0.65.4\out\extension.js:1:64837)
at c:\Users\zatki\.vscode\extensions\ms-vscode-remote.remote-ssh-0.65.4\out\extension.js:1:413357
at processTicksAndRejections (internal/process/task_queues.js:93:5)
[14:35:04.060] ------
As you can see, it prompted me twice for my password, before I stopped the connection attempt. No matter how many times I enter my password, whether it's right or wrong, nothing progresses past this point.
My primary motivation is to be able to use a persistent connection via "controlmasters" via a ProxyJump. However, it also makes sense to me that with a fully functional ssh in WSL, one should be able to use it in VSCode.
@roblourens just following up, as @UnicodeTreason wrote above, please let us know what we can do to help move this along!
Bumping this! :/
Bumping this again :(
@roblourens Maybe this is a niche-ask since there doesn't seem to be much follow-up from the community, but it is very well-defined and I think well-motivated. What can we do to keep it on the docket?
Improving upon the solutions by: @diablodale, @lancslingwood, and @cchan (thank you so much guys!)
With this improvement, there is no need to create a symbolic link. Just set the configurations below and you are done.
settings.json
"remote.SSH.path": "C:\\wsl-helpers\\vsc-ssh.bat",
"remote.SSH.configFile": "\\\\wsl$\\Ubuntu\\home\\yourusername\\.ssh\\config",
vsc-ssh.bat
@echo off
set v_params=%*
set v_params=%v_params:\=/%
set v_params=%v_params:c:=/mnt/c%
set v_params=%v_params:"=\"%
for /f "delims=" %%a in ('powershell -Command "& {'%v_params%' -replace '\/\/wsl\$\/[^\/]*',''}"') do set "v_params=%%a"
C:\Windows\system32\wsl.exe ssh %v_params%
Note: If you want to use a non-default distro, you can edit the vsc-ssh.bat file with something like ... wsl.exe -d Ubuntu ...
@jtmotox
C:\Windows\system32\bash.exe -ic "ssh %v_params%"
Shouldn't be this part something like of wsl.exe -d Ubuntu ...bash -ic "ssh .."
, otherwise it's unclear for me how specific distro is called?
Shouldn't be this part something like of
wsl.exe -d Ubuntu ...bash -ic "ssh .."
, otherwise it's unclear for me how specific distro is called?
Good catch. I use my default distro for ssh connections so I didn't think of this. I have updated my comment to use wsl instead of bash so you can pass the -d flag now to specify which distro to use.
I was having trouble getting a passphrase prompt and was able to get there by following @JtMotoX solution above (except I used "remote.SSH.configFile": "/home/username/.ssh/config"
as the "\\\\wsl$\..."
version did not work for me). However, like @zatkins2, after entering my passphrase remote-SSH hangs (with both correct and incorrect passwords), although I do not get multiple prompts:
[13:05:07.995] Log Level: 2
[13:05:08.004] remote-ssh@0.65.8
[13:05:08.005] win32 x64
[13:05:08.007] SSH Resolver called for "ssh-remote+<server>", attempt 1
[13:05:08.008] "remote.SSH.useLocalServer": false
[13:05:08.009] "remote.SSH.showLoginTerminal": true
[13:05:08.009] "remote.SSH.remotePlatform": {}
[13:05:08.009] "remote.SSH.path": C:\Users\taryn\bin\vsc_ssh.bat
[13:05:08.009] "remote.SSH.configFile": /home/taryn/.ssh/config
[13:05:08.010] "remote.SSH.useFlock": true
[13:05:08.010] "remote.SSH.lockfilesInTmp": false
[13:05:08.010] "remote.SSH.localServerDownload": auto
[13:05:08.010] "remote.SSH.remoteServerListenOnSocket": false
[13:05:08.011] "remote.SSH.showLoginTerminal": true
[13:05:08.011] "remote.SSH.defaultExtensions": []
[13:05:08.011] "remote.SSH.loglevel": 2
[13:05:08.012] SSH Resolver called for host: <server>
[13:05:08.012] Setting up SSH remote "<server>"
[13:05:08.048] Using commit id "83bd43bc519d15e50c4272c6cf5c1479df196a4d" and quality "stable" for server
[13:05:08.055] Install and start server if needed
[13:05:08.683] Checking ssh with "C:\Users\taryn\bin\vsc_ssh.bat -V"
[13:05:09.108] > OpenSSH_8.2p1 Ubuntu-4ubuntu0.2, OpenSSL 1.1.1f 31 Mar 2020
[13:05:09.198] Using SSH config file "/home/taryn/.ssh/config"
[13:05:09.198] Running script with connection command: "C:\Users\taryn\bin\vsc_ssh.bat" -T -D 53841 -F "/home/taryn/.ssh/config" "<server>" bash
[13:05:09.205] Terminal shell path: C:\WINDOWS\System32\cmd.exe
[13:05:10.044] >
>
>
> ]0;C:\WINDOWS\System32\cmd.exe
>
>
[13:05:10.045] Got some output, clearing connection timeout
[13:05:10.360] >
>
>
[13:05:11.155] > Enter passphrase for key '/home/taryn/.ssh/id_rsa':
[13:05:18.889] > ^Enter passphrase for key '/home/taryn/.ssh/id_rsa': ^CTerminate batch job (Y/N)?
>
>
[13:05:18.914] > ^C
[13:05:20.259] "install" terminal command done
[13:05:20.260] Install terminal quit with output: ^C
As far as I can tell (I know very little about how this stuff works), the problem is arising with Running script with connection command: "C:\Users\taryn\bin\vsc_ssh.bat" -T -D 53841 -F "/home/taryn/.ssh/config" "<server>" bash
. If I run this in cmd, it hangs after passphrase -- but if I remove bash
from the end, I can connect. I can also connect from bash. So I think I need to either remove bash
from the end of that connection command, or change the terminal shell path to bash instead of cmd. I haven't been able to figure that out yet...
Running script with connection command: "C:\Users\taryn\bin\vsc_ssh.bat" -T -D 53841 -F "/home/taryn/.ssh/config" "
" bash. If I run this in cmd, it hangs after passphrase
@tarynblack It might not actually be hung but you might unknowingly be at a bash prompt. When it "hangs", can you try typing "whoami" (without the quotes) and hit enter and see if it returns with anything?
@JtMotoX yes, whoami returns my username for the server (in cmd).
In VS Code though, after I enter my passphrase it just continues to say "Opening Remote" in the status bar, and on the right there's a popup that says "Setting up SSH Host
@tarynblack since it returns your username, then it is doing exactly what it should.
I think now you are running into a different issue which I have found others reporting here (https://github.com/microsoft/vscode-remote-release/issues/434) and here (https://github.com/microsoft/vscode-remote-release/issues/1202). Do you have a "RemoteCommand" section in your config? Are you able to paste the config section for your \<server> with any IP's or hostnames redacted?
Thanks @JtMotoX! I'll take a look at those issues. I do not have a "RemoteCommand" section in my config. My entire config is:
Host <server>
HostName <server>
User <username>
IdentityFile ~/.ssh/id_rsa
@tarynblack yeah that is a pretty simple config so I'm not sure what is going on. Are you using wsl (original) or wsl2?
On another note.
... (except I used
"remote.SSH.configFile": "/home/username/.ssh/config"
as the"\\\\wsl$\..."
version did not work for me).
I didn't realize that using the underlying filepath would work for this setting but I tested it and it works. I have updated my original post with this since it is simpler. Thanks.
I'm also seeing this issue @roblourens. Any idea as to when it would be resolved. I cannot use the remote-ssh extension with my configured keypairs under WSL.
I have the same behavior as you actually, @tarynblack . Might be because of a version update since I first reported the problem.
settings.json
"remote.SSH.path": "C:\\wsl-helpers\\vsc-ssh.bat", "remote.SSH.configFile": "\\\\wsl$\\Ubuntu\\home\\yourusername\\.ssh\\config",
... Note: If you want to use a non-default distro, you can edit the vsc-ssh.bat file with something like
... wsl.exe -d Ubuntu ...
Amazing job guys!
I want to improve this a little bit, for anyone who are using non-default distro or had changed your wsl installation folder like me, you will need to change the last line of vsc-ssh.bat
as shown below:
C:\Windows\system32\wsl.exe -d your-distro-name ssh %v_params% For example: C:\Windows\system32\wsl.exe -d Ubuntu-20.04 ssh %v_params%
And in the settings.json
:
"remote.SSH.path": "C:\\wsl-helpers\\vsc-ssh.bat", "remote.SSH.configFile": "\\\\wsl$\\home\\yourusername\\.ssh\\config",
Hope this will help you guys!
All-
If I use \\\\wsl$\\Ubuntu\\home\\ubuntu\\.ssh\\config
, I cannot open the config file in VS Code. But if I use \\wsl$\Ubuntu\home\ubuntu\.ssh\config
, I can open the config file.
However, with the latter, I get the error when trying to connect:
Can't open user config file \\wsl$\\Ubuntu\\home\\ubuntu\\.ssh\\config: No such file or directory
What's going on here?
@jtele2 Since this is a setting in a json config file, you have to escape any backslashes, which means you have to add a backslash before any backslash. If you do not have the double backslashes in your settings.json config, then VSC will not parse it correctly. If you are trying to open the file directly in VSC, then yes you use the single slashes in your file path. If you are adding the file path to the settings.json file, then you need to use double slashes.
I was able to get the options suggested by @JtMotoX working for me with WSL1, replicated below. @CoolCold comment also gave me the idea I needed to get X11 pass-through working as well and I wanted to point out that specific benefit for anyone else looking for that functionality.
json settings:
"remote.SSH.path": "C:\\Users\\username\\Documents\\ssh.bat",
"remote.SSH.configFile": "\\\\wsl$\\Ubuntu\\home\\username\\.ssh\\config",
bat file:
@echo off
set v_params=%*
set v_params=%v_params:\=/%
set v_params=%v_params:c:=/mnt/c%
set v_params=%v_params:"=\"%
for /f "delims=" %%a in ('powershell -Command "& {'%v_params%' -replace '\/\/wsl\$\/[^\/]*',''}"') do set "v_params=%%a"
C:\Windows\system32\wsl.exe -e bash -ic "ssh -Y %v_params%"
The final bat command will launch ssh with your bash profile environment settings, so if you've configured your display variable in WSL that will be forwarded to the remote connection. Note that I had to use the -Y flag, the x11 forwarding flag in the vscode remote module did not affect this. Thanks for the help all.
Also facing this issue, i dont want to have two directories where my keys are,
since WSL is far easier to use for actual development, i'm only using WSL to develop and managing SSH Keys.
Keeps everything organized and seperated, preventing cluttering windows with for example nodejs.
But VS Code is still a windows executable and i'd like to connect to my configured wsl ssh hosts through my wsl ssh private keys, please ððŧ
Steps to Reproduce:
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
These closed issues also make it look as though it WAS added recently: https://github.com/microsoft/vscode-remote-release/issues/359 https://github.com/microsoft/vscode-remote-release/issues/448