在 CentOS 上搭建 FTP 服务器(FTPS,即 FTP over SSL/TLS),最常用的是 vsftpd + SSL。下面我按 最简可运行方案 给你一步步来,适合 CentOS 7 / 8 / Stream。
yum install -y vsftpd
(CentOS 8 / Stream 用 dnf install -y vsftpd)
mkdir -p /etc/vsftpd/ssl
openssl req -x509 -nodes -days 365 \
-newkey rsa:2048 \
-keyout /etc/vsftpd/ssl/vsftpd.key \
-out /etc/vsftpd/ssl/vsftpd.crt
一路回车即可(Common Name 建议填服务器 IP 或域名)。
编辑配置文件:
vim /etc/vsftpd/vsftpd.conf
# 基础
anonymous_enable=NO
local_enable=YES
write_enable=YES
local_umask=022
# 被动模式(非常重要)
pasv_enable=YES
pasv_min_port=30000
pasv_max_port=31000
# SSL / TLS(FTPS 关键)
ssl_enable=YES
allow_anon_ssl=NO
force_local_data_ssl=YES
force_local_logins_ssl=YES
ssl_tlsv1=YES
ssl_sslv2=NO
ssl_sslv3=NO
rsa_cert_file=/etc/vsftpd/ssl/vsftpd.crt
rsa_private_key_file=/etc/vsftpd/ssl/vsftpd.key
# 安全
chroot_local_user=YES
allow_writeable_chroot=YES
# 日志
xferlog_enable=YES
log_ftp_protocol=YES
firewall-cmd --permanent --add-port=21/tcp
firewall-cmd --permanent --add-port=30000-31000/tcp
firewall-cmd --reload
✅ 安全组也要放行 21 和 30000–31000
systemctl enable vsftpd
systemctl start vsftpd
systemctl status vsftpd
useradd ftpuser
passwd ftpuser
用户默认家目录:
/home/ftpuser
| 客户端 | 设置 |
|---|---|
| FileZilla | 协议:FTP over TLS |
| WinSCP | 协议:FTP + TLS/SSL |
| lftp | set ftp:ssl-force true |
❌ 不要用普通 FTP(会被拒绝)
setenforce 0
测试是否 SELinux 问题
chmod 755 /home/ftpuser
你可以直接告诉我:
我可以给你 专用配置 + 排错命令,甚至帮你改成 SFTP(更推荐)。