vsFTPd服务器:ls命令正常但LIST失效,SFTP无法锁定家目录
vsFTPd 问题排查:LIST命令失败与用户家目录锁定问题
一、ls正常但quote LIST失效的原因
ls是FTP客户端的封装命令,客户端会自动完成数据连接协商(比如日志里的EPRT主动模式协商),再向服务器发送LIST请求,所以能成功建立数据通道获取目录。而quote LIST是直接给服务器发LIST指令,跳过了客户端自动处理的前置步骤,必须手动先通过PORT/PASV建立数据通道。
从日志的227 Entering Passive Mode (0,0,0,0,190,115)可以看出核心问题:vsFTPd未正确配置被动模式的对外IP,返回了无效的0.0.0.0地址,导致客户端无法连接数据端口,最终触发425 Failed to establish connection错误。
修复步骤:
- 编辑
/etc/vsftpd.conf,添加或修改以下配置:pasv_enable=YES pasv_address=你的服务器实际IP(本地/公网) pasv_min_port=60000 pasv_max_port=65000 - 重启vsftpd服务:
systemctl restart vsftpd - 若为远程连接,确保防火墙开放上述被动端口范围。
二、SFTP与FTP家目录锁定的独立配置
vsFTPd仅处理FTP协议,SFTP属于SSH子服务,两者的家目录锁定配置完全分开:
- FTP锁定家目录:在
/etc/vsftpd.conf中设置:chroot_local_user=YES allow_writeable_chroot=YES # 若需用户在家目录有写入权限则添加 - SFTP锁定家目录:编辑
/etc/ssh/sshd_config,添加用户匹配规则:
注意:Match User aaaa ChrootDirectory /home/aaaa ForceCommand internal-sftp AllowTcpForwarding no X11Forwarding noChrootDirectory指定的目录必须由root用户拥有,权限设为755或更严格,否则sshd会拒绝登录。 - 重启sshd服务:
systemctl restart sshd
附操作日志:
root@zzzzzz:~# ftp localhost Connected to localhost. 220 (vsFTPd 3.0.3) Name (localhost:root): aaaa 331 Please specify the password. Password: 230 Login successful. Remote system type is UNIX. Using binary mode to transfer files. ftp> ls 200 EPRT command successful. Consider using EPSV. 150 Here comes the directory listing. ------------------------------- 226 Directory send OK. ftp> quote LIST 425 Use PORT or PASV first. ftp> quote PASV 227 Entering Passive Mode (0,0,0,0,190,115). ftp> quote LIST ---- 1 minute delay ---- 425 Failed to establish connection. ftp> recv (remote-file) robots.txt (local-file) 111 local: 111 remote: robots.txt 200 EPRT command successful. Consider using EPSV. 150 Opening BINARY mode data connection for robots.txt (23 bytes). 226 Transfer complete. 23 bytes received in 0.02 secs (1.4171 kB/s) ftp> quote RECV 500 Unknown command. ftp> quote RETR 425 Use PORT or PASV first. ftp> quote PASV 227 Entering Passive Mode (0,0,0,0,66,14). ftp> quote RETR 550 Failed to open file. ftp> quote RETR robots.txt ---- 1 minute delay ---- 425 Failed to establish connection. ftp>
内容的提问来源于stack exchange,提问作者alex6999
相关产品推荐
相关产品推荐

