clion-wsl icon indicating copy to clipboard operation
clion-wsl copied to clipboard

Script isn't working

Open feinstein opened this issue 5 years ago • 8 comments

I just tried the configurations here and I get:

ssh: connect to host localhost port 2222: Connection refused

I am using the latest version of Windows 10 and the Ubuntu 18.04.3 LTS on the WSL.

feinstein avatar Aug 27 '19 20:08 feinstein

This started happening to me about a week ago, and I don't know why or how to fix.

After some experimentation, I found I can connect to localhost port 2222 when I am at work (on a "Domain" network, in Windows parlance) but not when at home (on a "Private" network). Note: I used to be able to do both.

I tried running sshd in "Debug" mode in WSL, and get a little more info below:

$ sudo service ssh stop
 * Stopping OpenBSD Secure Shell server sshd                                                                     [ OK ]

$ sudo /usr/sbin/sshd -d
/etc/ssh/sshd_config line 127: Deprecated option UsePrivilegeSeparation
debug1: sshd version OpenSSH_7.6, OpenSSL 1.0.2n  7 Dec 2017
debug1: private host key #0: REDACTED
debug1: private host key #1: REDACTED
debug1: private host key #2: REDACTED
debug1: rexec_argv[0]='/usr/sbin/sshd'
debug1: rexec_argv[1]='-d'
debug1: Set /proc/self/oom_score_adj from 0 to -1000
debug1: Bind to port 2222 on 127.0.0.1.
Bind to port 2222 on 127.0.0.1 failed: Permission denied.
Cannot bind any address.

It definitely looks to me like the problem is something happening on the WSL side, although still not sure how to fix this issue.

jthelin avatar Nov 13 '19 16:11 jthelin

Did you find out the issue? I'm having the exact same problem. It magically goes away after trying some restarts and reinstalling but then comes back, usually after a Windows upgrade.

ChisholmKyle avatar Feb 13 '20 13:02 ChisholmKyle

No, I just stopped using WSL.

feinstein avatar Feb 13 '20 21:02 feinstein

+1, the exact same problem.

xlicz avatar Apr 03 '20 10:04 xlicz

You can just follow some common tutorial to easily setup SSH server. Basically all you need is:

  1. sudo apt install openssh-server
  2. sudo service ssh --full-restart to start the SSH server
  3. service ssh status to check whether the SSH server is running

Thats basically it. Now the SSH is running on port 22, but thats the only difference from what the script and guide says.

Also don't forget sudo apt install -y cmake gcc clang gdb valgrind build-essential to prepare linux environment for compiling C

If you don't know the username - run whoami in WSL and the password is what you have setup during WSL setup. If you didn't set your password anywhere and you are using default user ubuntu that has no password by default, you still need to set password to be able to connect over SSH. Just run passwd and follow on-screen instructions

risinek avatar May 02 '20 11:05 risinek

On the WSL front, I think this might be an issue with Clion itself preferring ipv4 when it comes to WSL.

So if I have a WSL instance running a docker container exposing a port over 2222, I can ssh that fine from windows, but Clion can't find it with ssh - p 2222 root@localhost. Clion will report connection refused.

Now, on a related sidenote, if I try and ssh 127.0.0.1 from Windows on port 2222, that will get connection refused too (ipv4).

In WSL, it'll work if you use the internal WSL container's ipv4 IP, but unfortunately that changes on every reboot so that can't be depended upon long term.

However.... if you look in the windows hosts file, you can find this comment:

# localhost name resolution is handled within DNS itself.
#	127.0.0.1       localhost
#	::1             localhost

So ::1 is the ipv6 ip for localhost, and amusingly, if you run ssh -p 2222 root@::1 from windows (which feels barmy) it will actually work. So I'm thinking that Windows actually only does IP forwarding for ipv6 for these forwarded ports.

So if you use the ipv6 localhost [::1] (yes with the square brackets because Clion needs them), it will actually work:

image

Hope this helps someone because google landed me here.

fquinner avatar Oct 08 '20 10:10 fquinner

I was able to resolve this by taking two steps:

  1. Changed the ListenAddress to 0.0.0.0 . I think that was the necessary step here.
  2. Changed the port to 2828. I'm not sure if this was necessary or not.

These two steps allowed me to get this to work.

freemansw1 avatar Dec 29 '20 00:12 freemansw1

I was able to resolve this by taking two steps:

  1. Changed the ListenAddress to 0.0.0.0 . I think that was the necessary step here.
  2. Changed the port to 2828. I'm not sure if this was necessary or not.

These two steps allowed me to get this to work.

It is helpful! Changing the port.

jackwener avatar Aug 09 '21 16:08 jackwener