在 CentOS 上搭建 FTPServer(FTP 服务) 时报错,常见原因主要集中在 服务未安装/未启动、防火墙/SELinux、配置错误、被动模式端口 等方面。下面按「常见报错 → 原因 → 解决办法」给你一个排查清单。
connect: Connection refused
500 OOPS: vsftpd not running
# 安装
yum install -y vsftpd
# 启动
systemctl start vsftpd
# 开机自启
systemctl enable vsftpd
# 查看状态
systemctl status vsftpd
421 Service not available
无法连接服务器
# FTP 控制端口
firewall-cmd --add-service=ftp --permanent
firewall-cmd --reload
如果是 被动模式(PASV),还要开放被动端口范围(见下文)。
550 Failed to open file
500 OOPS: cannot change directory
SELinux 限制了 FTP 访问目录
# 允许 FTP 访问家目录
setsebool -P ftp_home_dir on
# 允许匿名写(如需要)
setsebool -P allow_ftpd_anon_write on
# 查看 SELinux 状态
getenforce
如测试环境可临时关闭:
setenforce 0
227 Entering Passive Mode
无法读取目录列表
编辑 /etc/vsftpd/vsftpd.conf:
pasv_enable=YES
pasv_min_port=30000
pasv_max_port=31000
pasv_address=你的服务器公网IP
然后:
firewall-cmd --add-port=30000-31000/tcp --permanent
firewall-cmd --reload
systemctl restart vsftpd
530 Login incorrect
检查:
local_enable=YES
500 OOPS: vsftpd: refusing to run with writable root inside chroot()
解决(CentOS 新版本):
allow_writeable_chroot=YES
vsftpd: config error
vsftpd /etc/vsftpd/vsftpd.conf
或查看日志:
journalctl -xe
/var/log/messages
/var/log/secure
如果你愿意,可以把 完整报错信息 或 vsftpd.conf 配置 发出来,我可以:
你现在是:本地用户 FTP / 匿名 FTP / 虚拟用户 / 显式 FTPS 哪一种?