SSH-ing into a Windows WSL Linux Subsystem

Assuming you have installed and setup your favorite Linux distribution under the Windows 10 WSL, you have to make a couple of tweaks before you can actually SSH into it. A fantastic guide to making your Windows 10 PC behave like a respectable Linux dev environment which covers this and so much more can be found here. In this post, I am just extracting the SSH setup recipe with slight modifications/extensions (publishing it here for my own quick and stable reference, if nothing else):

  1. In the WSL bash shell, Reinstall OpenSSH by:

    sudo dpkg-reconfigure openssh-server
  2. In the WSL bash shell, edit the “/etc/ssh/sshd_config” configuration file to set the port to 2222 and allow password authentication:

    Port 2222
    # ...
    PasswordAuthentication yes

    (The reason for changing the port is that the default port 22 might be used by windows. Also, as noted in the original guide, you should setup the machine for SSH key-based access, not just for security but also for efficiency.)

  3. Open up port 2222 in the windows firewall:

    • In the Windows Start menu, type “WF.msc”.
    • In the “Windows Firewall with Advanced Security” section, click on “Inbound Rules”.
    • Add a new rule for TCP 2222 and allow the connection:
      • “Actions” > “New Rule …”
      • “What type of rule would you like to create?”: “Port
      • “Does this rule apply to TCP or UDP? “TCP
      • “Does this rule apply to all local ports or specific local ports”: “Specific local ports: 2222
      • “What action should be taken when a connection matches the specified conditions”: “Allow the connection
      • “When does this rule apply” (check all boxes)
  4. Restart SSH serwer in the WSL bash shell:

    sudo service ssh --full-restart
  5. Get the IP address of the WSL machine by running ifconfig:

    # or, if you want to be fancy
    # ifconfig | grep -A1 eth0: | grep inet | sed -e 's/\s\+inet \(.*\) netmask.*/\1/'
  6. And SSH away!

I HIGHLY recommend that you read, and implement, both part 1 and part 2 of the guide mentioned above. Your Windows/Linux experience will work out to be not just far more productive, but also far more efficient and enjoyable!