Skip to content

SSH into WSL from a remote machine not working #5131

Closed

Description

Please fill out the below information:

  • Your Windows build number: Microsoft Windows [Version 10.0.19613.1000]

  • What you're doing and what's happening:

I did modify the /etc/ssh/sshd_config to port 2222, and PasswordAuthentication true, and AllowUsers is added.

port 2222 is exposed, and listening

image

I can connect from the same machine

image

  • What's wrong / what should be happening instead:

I cannot connect to ssh from and other host in my network. The port is not exposed even if I disable firewall on Domain, Private, and Public network.

Activity

  1. nunix commented on Apr 24, 2020

    @nunix

    hi Bart,

    this is actually a network "behavior" on Windows side. Your issue is that the port 2222 (or any ports from WSL->Windows actually) are bound to 127.0.0.1 on Windows side instead of 0.0.0.0 or your Windows IP address.

    A workaround would be to tunnel your port towards your IP address for example:
    netsh interface portproxy add v4tov4 listenaddress=localhost listenport=2222 connectaddress=<your IP address> connectport=2222

    And, if you really want it "constant", then you can had this to your Powershell $PROFILE (or a script launched by a windows task):

    # Get your IP
    $env:MainIP=(Test-Connection -ComputerName (hostname) -Count 1).IPV4Address.toString()
    # Cleans the tunnels table
    (netsh interface portproxy reset all)
    (netsh interface portproxy add v4tov4 listenaddress=localhost listenport=2222 connectaddress=$env:MainIP connectport=2222)

    Hope this helps.

    WSL Corsair

  2. bplasmeijer commented on Apr 25, 2020

    @bplasmeijer
    Author
    # Get your IP
    $env:MainIP=(Test-Connection -ComputerName (hostname) -Count 1).IPV4Address.toString()
    # Cleans the tunnels table
    (netsh interface portproxy reset all)
    (netsh interface portproxy add v4tov4 listenaddress=localhost listenport=2222 connectaddress=$env:MainIP connectport=2222)

    hi Nuno do Carmo (@nunix)
    no access from the remote
    image:
    no firewall enabled on machine
    image
    more tips Nuno do Carmo (@nunix) ?

  3. nunix commented on Apr 25, 2020

    @nunix

    Ok my bad, I read it the "wrong way", let's try to invert the listening and connection

    (netsh interface portproxy reset all)
    (netsh interface portproxy add v4tov4 listenaddress=$env:MainIP listenport=2222 connectaddress=localhost connectport=2222)

    so you are waiting a connection done on the main IP from your external computer and then it will tunnel to your localhost.
    And if it still doesn't work, try mapping the connectaddress to your WSL IP

  4. bplasmeijer commented on Apr 25, 2020

    @bplasmeijer
    Author

    Ok my bad, I read it the "wrong way", let's try to invert the listening and connection

    (netsh interface portproxy reset all)
    (netsh interface portproxy add v4tov4 listenaddress=$env:MainIP listenport=2222 connectaddress=localhost connectport=2222)

    so you are waiting a connection done on the main IP from your external computer and then it will tunnel to your localhost.
    And if it still doesn't work, try mapping the connectaddress to your WSL IP

    After reading your message Nuno do Carmo (@nunix) , I agree to invert the listening, and YES, it works...

    Now the big question for Craig Loewen (@craigloewen-msft) and Hayden Barnes (@sirredbeard), I did go into the other route based on netstat info, and firewall settings. Do we want this "behavior" with the portproxy on WSL?

    Windows Firewall dialog for a port rule:

    image

  5. 1ycx commented on Jul 16, 2020

    @1ycx

    Was this issue solved ? I've been trying to do the same thing.
    Say I have two machines, A and B.

    A: Win 10 Laptop
    B: Win 10 PC with WSL installed

    Only Ubuntu18.04 is installed on WSL.

    On B - I have configured firewall for inbound port 2222 for private and domain networks.

    I have OpenSSH server running on Windows in B and also SSH server running on WSL in B.
    I use rsa public keys to authenticate - A (CMD/Powershell) to B's OpenSSH Windows server and B (CMD/Powershell) to B's SSH Server on WSL.
    I can SSH from B into its WSL, but I can't SSH from A to B's WSL directly.

    # On B, Powershell
    PS C:\Users\kogam> netstat -ao | select-string 2222
    
      TCP    127.0.0.1:2222         HOME-3700X-2060:0      LISTENING       11556
    
    # On B, Powershell
    PS C:\Users\kogam> Get-Process -Id 11556
    
     NPM(K)    PM(M)      WS(M)     CPU(s)      Id  SI ProcessName
     ------    -----      -----     ------      --  -- -----------
         11     1.19       4.73       1.39   11556   1 wslhost
    
    # On B, WSL
    kogam22@HOME-3700X-2060:~$ netstat -ao
    Active Internet connections (servers and established)
    Proto Recv-Q Send-Q Local Address           Foreign Address         State       Timer
    tcp        0      0 0.0.0.0:2222            0.0.0.0:*               LISTEN      off (0.00/0/0)
    tcp6       0      0 [::]:2222               [::]:*                  LISTEN      off (0.00/0/0)
    tcp6       0      0 ip6-localhost:43024     ip6-localhost:2222      ESTABLISHED off (0.00/0/0)
    tcp6       0      0 ip6-localhost:2222      ip6-localhost:43024     ESTABLISHED keepalive (6540.41/0/0)
    Active UNIX domain sockets (servers and established)
    Proto RefCnt Flags       Type       State         I-Node   Path
    unix  2      [ ACC ]     SEQPACKET  LISTENING     15060    /run/WSL/1303_interop
    unix  2      [ ACC ]     SEQPACKET  LISTENING     20734    /run/WSL/1822_interop
    unix  3      [ ]         STREAM     CONNECTED     15814
    unix  3      [ ]         STREAM     CONNECTED     15813
  6. therealkenc commented on Sep 1, 2020

    @therealkenc

    /dupe #4150

  7. ghost closed this as completedon Sep 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions