在 CentOS 上搭建 FTP 服务器 并配置用户,通常使用的是 vsftpd(Very Secure FTP Daemon)。下面给你一套最常见、可用的配置步骤,适合 CentOS 7 / 8 / Stream。
yum install -y vsftpd
# 或 CentOS 8 / Stream
dnf install -y vsftpd
启动并设置开机自启:
systemctl start vsftpd
systemctl enable vsftpd
useradd ftpuser
passwd ftpuser
设置用户家目录(FTP 登录后默认目录):
usermod -d /home/ftpuser ftpuser
编辑配置文件:
vi /etc/vsftpd/vsftpd.conf
anonymous_enable=NO
local_enable=YES
write_enable=YES
local_umask=022
chroot_local_user=YES
allow_writeable_chroot=YES
✅ 说明
anonymous_enable=NO:禁止匿名登录local_enable=YES:允许系统用户登录chroot_local_user=YES:限制用户只能访问自己的目录allow_writeable_chroot=YES:允许在 chroot 目录中写文件
保存后重启:
systemctl restart vsftpd
firewall-cmd --permanent --add-service=ftp
firewall-cmd --reload
setsebool -P ftp_home_dir on
如果仍有问题:
getsebool -a | grep ftp
ftp localhost
usermod -s /sbin/nologin ftpuser
如果你不想创建系统用户,可以用:
vsftpd + PAM + 虚拟用户适合:
需要的话我可以单独写一份 虚拟用户配置教程。
| 问题 | 原因 |
|---|---|
| 530 Login incorrect | 用户被 nologin / PAM 限制 |
| 500 OOPS chroot | 没加 allow_writeable_chroot |
| 无法上传 | write_enable=NO |
| 连接超时 | 防火墙 / SELinux |
如果你告诉我:
我可以给你定制版配置。