1. 通过ssh直接连接台式机的WSL
基本上参考pimooook这篇博客的流程,不过可能是因为我的台式机也开了ssh的原因,所以WSL用22端口冲突了,后面改成2222就能正常连接了。在开机自启的指令中记得修改端口:
CreateObject("Wscript.Shell").run "wsl -d Ubuntu -u root -e /etc/init.d/ssh start",vbhide
wscript.sleep 1000 * 10
Set Shell=CreateObject("Shell.Application")
Shell.ShellExecute "cmd.exe","/c netsh interface portproxy add v4tov4 listenaddress=0.0.0.0 listenport=2222 connectaddress=wslhost connectport=2222","C:\Windows\System32\","runas",0
可能还需要在台式机修改防火墙
netsh advfirewall firewall add rule name="OpenSSH" dir=in action=allow protocol=TCP localport=2222
2. 使用vscode连接台式WSL
经过上面步骤的配置,只需要在本地的vscode安装Remote Development插件然后正常配置即可,唯一需要注意的是操作系统要选linux,因为之前连台式的时候选的是windows结果一直连不上,查看log才发现是系统选错了
如果选错了可以在vscode的设置里搜索remote.ssh进行修改: