clion-wsl
clion-wsl copied to clipboard
Script isn't working
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.
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.
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.
No, I just stopped using WSL.
+1, the exact same problem.
You can just follow some common tutorial to easily setup SSH server. Basically all you need is:
-
sudo apt install openssh-server
-
sudo service ssh --full-restart
to start the SSH server -
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
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:
Hope this helps someone because google landed me here.
I was able to resolve this by taking two steps:
- Changed the
ListenAddress
to0.0.0.0
. I think that was the necessary step here. - 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.
I was able to resolve this by taking two steps:
- Changed the
ListenAddress
to0.0.0.0
. I think that was the necessary step here.- 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.