栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

wsl配置ssh和自启动

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

wsl配置ssh和自启动

1.配置Linux子系统ssh

先把win的ssh服务关了,因为Ubuntu20.04子系统自带的ssh服务无法连接,需卸载后重新安装。

卸载ssh服务

apt remove openssh-server

重装ssh服务

apt install openssh-server

修改配置

# /etc/ssh/sshd_config
Port 22
ListenAddress 0.0.0.0
PermitRootLogin yes
PasswordAuthentication yes

重启服务

service ssh restart

测试

ssh root@localhost

设置SSH自启动

# /etc/init.wsl
service docker start

编辑win注册表

HKEY_CURRENT_USERSOFTWAREMicrosoftWindowsCurrentVersionRun
下添加一个REG_SZ 类型的值,名称自定义,值为:
mshta vbscript:CreateObject(“Wscript.Shell”).Run(“wsl -d Ubuntu-20.04 -u root bash /etc/init.wsl”,0,TRUE)(window.close)

设置端口转发
wsl 子系统的ip并不是和Win公用的内网ip,所以需要将Win收到的请求转发到wsl子系统中
在linux子系统下ifconfig查看ip,在powershell中执行:

# ip用wsl子系统的ip替换,注意去掉中括号
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

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/321319.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号