This is a manual for those who are struggling with WSL2's isolated network. Most of ideas come from WSL#4150 issue, so it's a summary of core comments. It will be helpful for people who want to open an ssh server on WSL2.
wslbridge.ps1
was forked from edwindijas's comment, and bypassing executionPolicy idea came from gstorelli.
- Install openssh-server.
- Edit
/etc/ssh/sshd_config
if you want. - Open
/etc/sudoers
in WSL2 and append%sudo ALL=NOPASSWD: /usr/sbin/service
. Thensudo service
won't ask you a password.
- Download this repository.
- Move wslbridge.ps1 into C:\scripts
- Open wslbridge.ps1 in a editor (e.g. notepad) and add ports that you need.
- Open (
Port forwarding.ps1
,Services for WSL2.ps1
) and replace {password} with yours. - Open powershell as admin privilege.
- Copy each script (
Port forwarding.ps1
,Services for WSL2.ps1
) and paste it to the shell.
Then, now you open task scheduler and check whether two tasks are sucessfully registered.