# On WSL distro
sudo apt remove openssh-server
sudo apt install openssh-server
sudo ufw allow ssh
sudo sh -c "echo '${USER} ALL=(root) NOPASSWD: /usr/sbin/service ssh start' >/etc/sudoers.d/service-ssh-start"
sudo nano /etc/ssh/sshd_config
# change the port from 22 because you might need it for windows ssh
>>> Port 2222
>>> # set PasswordAuthentication to yes
>>> PasswordAuthentication yes
>>> ctrl+x
sudo service ssh --full-restart
or
sudo service ssh start
sudo visudo
>>> %sudo ALL=(ALL:ALL) ALL
>>> %sudo ALL=NOPASSWD: /usr/sbin/sshd
# Allow port through firewall
# Add a Windows Task Scheduler to automatically start ssh server
Open Windows Task Scheduler
Create a Basic Task
In the Basic Task Window:
Under Create Basic Task
Name : Start Bash SSH Server
Description: Start the WSL SSh Serer via a bash command
Click Next to continue
Under Trigger
under When do you want the task to start? select When the Computer Starts
Click Next to continue
Under Action
Select Start a Program
Under Program/script: %windir%\System32\bash.exe
or
%windir%\System32\wsl.exe
with -d <distro_name> -c ...
Under Add arguments (optional): -c "sudo /etc/init.d/ssh start"
Click Next to continue
or
netsh interface portproxy add v4tov4 listenaddress=0.0.0.0 listenport=2222 connectaddress=$wsl_ip connectport=2222