Windows10开机自动启动WSL

在Ubuntu系统内创建文件/etc/init.wsl.sh

laoshanxi@DELL-DESK:~$ cat /etc/init.wsl.sh
#!/bin/bash
sudo -S service ssh start << EOF
laoshanxi
EOF

#sudo service nginx start
#sudo service php7.4-fpm start
#sudo service mysql start

# 运行bash.exe不退出
while true
do
        sleep 600
done

创建windows开机自动启动脚本C:\Users\Shaanxi\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\startwsl.vbs

Set ws = WScript.CreateObject("WScript.Shell")
cmd = "C:\Windows\System32\bash.exe -c ""bash /etc/init.wsl.sh"""
ws.Run cmd, 0, false
Set ws = Nothing
WScript.quit

在Powershell中设置22端口转发

# netsh interface portproxy add v4tov4 listenaddress=0.0.0.0 listenport=22 connectaddress=[IP] connectport=22
# netsh advfirewall firewall add rule name=WSL2 dir=in action=allow protocol=TCP localport=22

(2条消息) WSL安装ubuntu系统后配置开机启动_小小稣的博客-CSDN博客_wsl 开机启动
(2条消息) wsl配置ssh和自启动_echo HelloWorld的博客-CSDN博客_wsl 启动ssh

你可能感兴趣的:(Windows10开机自动启动WSL)