Win10和WSL Ubuntu 22.04.1 SSH远程连接

openssh-server配置

安装ssh服务

在Ubuntu20.04.1 LTS子系统安装openssh-serverUbuntu子系统中,执行一下命令:

sudo apt install openssh-server

编辑远程登录配置信息

修改/etc/ssh/sshd_config配置文件。

Ubuntu子系统中,执行一下命令:

vi /etc/ssh/sshd_config

1)修改PortListenAddress

 

 

 

2)修改PermitRootLogin 

 

 

3)修改PasswordAuthentication 

 

 

4)重动ssh服务.在Ubuntu子系统中,执行一下命令

    service ssh restart

ssh连接

远程连接

查看Ubuntu系统的地址,在子系统中执行下面的命令:

ifconfig

 

 

 1)在Win10 Power Shell下执行命令,将[IP][PORT]替换为wslIP和端口。

netsh interface portproxy add v4tov4 listenaddress=0.0.0.0 listenport=22 connectaddress=[IP] connectport=[PORT]

1)在Win10 Power Shell下执行命令,设置防火墙入站规则

netsh advfirewall firewall add rule name=WSL2 dir=in action=allow protocol=TCP localport=22

(也可以在防火墙-高级设置-入站规则中设置)

 

 

 设置完成后,就可以互相访问了

 

 

posted @ 2022-12-22 16:08  航行  阅读(2934)  评论(0编辑  收藏  举报