Connecting to the Windows Subsystem for Linux from

2019-04-10 01:56发布

问题:

I wish to debug a Linux C++ console application from VS2017, as in these tutorials:

Writing And Debugging Linux C Applications From Visual Studio Using The Windows Subsystem For Linux

targeting windows subsystem for Linux from visual studio

I have installed gdbserver and openssh-server in my WSL Ubuntu 16.04 installation, and sshd is running, but I cannot connect from VS2017. When I try, I get the error 'Connectivity Failure. Please make sure the host name and port number are correct'.

Both the host name and port number are correct as far as I am concerned. I know that WSL is still Beta, so I am assuming the problem has something to do with WSL (I recently installed the Windows 10 Creators Update so it is at least up to date, but I was expecting ssh to work with CU). I'm using Windows 10 version 1703, Build 15063.250.

Update I got Visual Studio to connect to my Ubuntu VM, which proves that it works and the problem must be with Bash on Windows. Nothing works with incoming connections, but outgoing connections work as expected.

Has anyone else had problems with connecting to WSL from Visual Studio 2017 in this way?

回答1:

Yes, it looks like this issue has already been reported here and here.

According to a recent comment on the latter thread, the problem has been resolved in Windows Insider build 16199. Depending on your circumstances, this might be an option for you until such time as the fix is incorporated into the release version.

If you are in a production environment, I recommend continuing to use the VM. I've not personally had too much trouble with Windows Insider builds, but there's always some risk involved.



回答2:

I faced the same problem with windows build with 16299 and am able to resolve the issue now. Posting the resolution in case it helps any other fellow programmer. (Though James might have already resolved it)

WSL lacks open ssh server by default. It has to be configured first for you to be able to connect with Visual Studio

To double check this. Go to Powershell and run netstat -an. I was not able to find anything running on localhost::22.

Follow these instructions toInstall open ssh on WSL install and run open ssh server.

In the output of nestat -an, now you should see something like below

  Proto  Local Address          Foreign Address        State
  TCP    0.0.0.0:22             0.0.0.0:0              LISTENING

Now, I am able to connect VS to WSL. :-) Cheers!!