Please visit these pages for more details about Network Shell (Netsh):
https://docs.microsoft.com/en-us/windows-server/networking/technologies/netsh/netsh-interface-portproxy
https://docs.microsoft.com/en-us/troubleshoot/windows-server/networking/netsh-advfirewall-firewall-control-firewall-behavior
Please make sure that you have installed Windows Subsystem for Linux (WSL 2):
Install Windows Subsystem for Linux (WSL 2)
To SSH into your Linux distro (WSL 2) from a remote machine, please follow these steps:
-
Install OpenSSH Server in your Linux distro.
Connect to your Linux distro. Enter: sudo apt innstall openssh-server
It not already installed, it may be useful to install "net-tools" package: sudo apt install net-tools
-
Configure /etc/ssh/sshd_config file.
Connect to your Linux distro. Enter: sudo vi /etc/ssh/sshd_config
You can set the local addresses that sshd should listen: "0.0.0.0".
Optionally, you can set the SSH port to another value (make sure that the port is not already used): "2222".
Restart OpenSSH Server: sudo service ssh restart
-
Forward port from Windows into your Linux WSL distro.
The portproxy server listens for messages sent to a specific port and IPv4 address and maps a port and IPv4 address to send the messages received after establishing a separate TCP connection.
listenaddress: Specifies the IPv4 address for which to listen ("0.0.0.0" any IPv4 address).
listenport: Specifies the IPv4 port on which to listen ("2222", you can choose any port you want).
connectaddress: Specifies the IPv4 address to which to connect ("172.26.110.211", this should be the address of your Linux WSL distro).
connectport: Specifies the IPv4 port to which to connect ("2222", must match the port your set for your sshd on your Linux WSL distro).
To check the Port:
-
Add a new firewall rule to enable the port.
To check the rule:
-
To test your configuration, open a terminal in a remote machine.
Enter: ssh mtitek@192.168.2.15 -p 2222
Replace mtitek with the user you have ceated for your Linux distro.
Replace 192.168.2.15 with the IP address of your Windows machine.
Notes:
To delete the firewall rule:
To delete the IPv4 port and address from the list of IPv4 ports and addresses for which the server listens.: