在windows下WSL2 ubuntu 20.4使用filezilla客户端使用SSH传输文件
1. SSH配置
打开WSL的终端窗口
1.1 ssh服务安装
Ubuntu20.04子系统自带的SSH服务无法连接,需卸载后重新安装。
- 卸载SSH服务
sudo apt purge openssh-server
- 重装SSH服务
sudo apt install openssh-server
1.2 修改配置信息
sudo vim /etc/ssh/sshd_config
- 修改SSH服务监听端口和监听地址
- 修改SSH服务允许远程root用户登入
- 修改SSH服务允许使用用户名密码方式登入
1.3 设置开机自启
sudo systemctl enable ssh
1.4 重启WSL
打开Power Shell(管理员),打入以下命令
# 停止服务
net stop LxssManager
# 启动服务
net start LxssManager
1.5 启动ssh服务
进入WSL,敲入以下命令:
# 启动服务
sudo service ssh start
# 查看ssh服务状态
service ssh status
显示sshd is running
表示启动成功
2. ssh连接
2.1 本机连接
在Power Shell(管理员)中通过SSH命令连接WSL子系统。
ssh root@localhost -p 2222
其中2222为上面设置SSH服务监听端口。
成功显示:
2.2 远程连接
- 查看WSL的IP
打开WSL终端
# 安装ifconfig工具
sudo apt install net-tools
# 查看IP地址
ifconfig
- 端口映射
将端口转发到WSL,在Power Shell(管理员)下执行命令,将[IP]替换为WSL的IP。
netsh interface portproxy add v4tov4 listenaddress=0.0.0.0 listenport=9922 connectaddress=[WSL-IP] connectport=2222
# 查看已经有的端口转发
# netsh interface portproxy show all
# 删除所有已经有的转发
# netsh interface portproxy reset
- 开启防火墙
netsh advfirewall firewall add rule name=WSL2 dir=in action=allow protocol=TCP localport=9922
3. Filezilla连接WSL
设置【主机和端口】、【用户和密码】,点击“连接”
成功显示:
Q&A
1 WSL SSH:kex_exchange_identification
解决方案:WSL SSH kex_exchange_identification: read: Connection reset
2. SSH:Permission denied (publickey,password)
解决方案:
进入WSL,重置密码
sudo passwd