Connecting to the Windows Subsystem for Linux from Visual Studio 2017

Viewed 4813

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'.

Visual Studio 2017 Connect to Linux

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.

VS Connection Manager Dialog Box

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

2 Answers

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!!

Related