本地主机win11系统,wsl2:Ubuntu 20.04.4 LTS
1,更新linux
$ sudo apt-get update
li@li:~$ sudo apt-get update
[sudo] password for li:
Ign:1 http://mirrors.ustc.edu.cn/ubuntu precise-updates InRelease
Ign:2 http://mirrors.ustc.edu.cn/ubuntu precise InRelease
2,安装openssh-server
li@li:~$ sudo apt-get install openssh-server
Reading package lists... Done
Building dependency tree
Reading state information... Done
openssh-server is already the newest version (1:8.2p1-4ubuntu0.4).
0 upgraded, 0 newly installed, 0 to remove and 13 not upgraded.
3,配置sshd_config软件,端口使用默认的22端口即可
li@li:~$ sudo vim /etc/ssh/sshd_config,仅需要修改PasswordAuthentication,如下
# 是否允许使用密码登录 “是”
PasswordAuthentication yes
4,启动ssh
li@li:~$ sudo service ssh start
* Starting OpenBSD Secure Shell server sshd
PS:如果还不行,可以打开powershell(管理员打开),执行如下命令
netsh interface portproxy set v4tov4 listenport=22 listenaddress=0.0.0.0 connectport=21 connectaddress=172.18.69.154 >
5,通过以上配置后,使用MobaXterm软件可以ssh登录到wsl。