在 CentOS 下搭建和使用 FTP Server,常用的是 vsftpd(Very Secure FTP Daemon)。下面给你一套 从安装到使用的完整流程(适用于 CentOS 7 / CentOS Stream,8/9 类似)。
yum install -y vsftpd
systemctl start vsftpd
systemctl enable vsftpd
查看状态:
systemctl status vsftpd
firewall-cmd --permanent --add-service=ftp
firewall-cmd --reload
如果是云服务器,还需要在安全组中放行 TCP 21。
setenforce 0
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
✅ 推荐方式(生产环境)
setsebool -P ftp_home_dir on
setsebool -P allow_ftpd_full_access on
配置文件位置:
/etc/vsftpd/vsftpd.conf
anonymous_enable=NO
local_enable=YES
write_enable=YES
local_umask=022
dirmessage_enable=YES
xferlog_enable=YES
connect_from_port_20=YES
xferlog_std_format=YES
chroot_local_user=YES
allow_writeable_chroot=YES
listen=YES
✅ 说明:
anonymous_enable=NO:禁止匿名登录chroot_local_user=YES:用户限制在主目录allow_writeable_chroot=YES:防止登录失败修改后重启:
systemctl restart vsftpd
useradd -m ftpuser
passwd ftpuser
限制用户只能通过 FTP 登录(不能 SSH):
usermod -s /sbin/nologin ftpuser
ftp localhost
服务器IP21FTP只使用明文 FTP(或配置 FTPS)cat /var/log/secure
常见原因:
/etc/shellsecho /sbin/nologin >> /etc/shells
如果客户端在 NAT 后面,需要配置被动模式:
pasv_enable=YES
pasv_min_port=30000
pasv_max_port=31000
防火墙放行:
firewall-cmd --permanent --add-port=30000-31000/tcp
firewall-cmd --reload
如果你需要 加密 FTP,我可以单独给你一份 FTPS 配置教程(vsftpd + SSL)。
CentOS 下用 vsftpd 是最稳妥的 FTP Server 方案,配置简单、稳定、安全。
如果你告诉我:
我可以给你 一份完全适合你环境的配置文件。