在 CentOS 上搭建 FTPServer(FTP 服务),常见做法是使用 vsftpd(Very Secure FTP Daemon)。下面以 CentOS 7 / 8 为例,说明安装和配置步骤。
sudo yum install -y vsftpd
(CentOS 8 可用 dnf)
sudo dnf install -y vsftpd
systemctl start vsftpd
systemctl enable vsftpd
查看状态:
systemctl status vsftpd
firewall-cmd --permanent --add-service=ftp
firewall-cmd --reload
编辑 /etc/vsftpd/vsftpd.conf,添加:
pasv_min_port=30000
pasv_max_port=31000
防火墙开放端口:
firewall-cmd --permanent --add-port=30000-31000/tcp
firewall-cmd --reload
常用配置示例:
anonymous_enable=NO
local_enable=YES
write_enable=YES
chroot_local_user=YES
allow_writeable_chroot=YES
修改后重启:
systemctl restart vsftpd
useradd ftpuser
passwd ftpuser
设置用户目录(可选):
usermod -d /home/ftpuser ftpuser
允许 FTP 访问:
setsebool -P ftp_home_dir on
如仍报错,可临时测试:
setenforce 0
(生产环境不建议关闭 SELinux)
本地测试:
ftp localhost
或使用 FileZilla、WinSCP 等工具连接。
生成证书:
openssl req -x509 -nodes -days 365 -newkey rsa:2048 \
-keyout /etc/vsftpd/vsftpd.pem -out /etc/vsftpd/vsftpd.pem
配置 vsftpd:
ssl_enable=YES
rsa_cert_file=/etc/vsftpd/vsftpd.pem
rsa_private_key_file=/etc/vsftpd/vsftpd.pem
force_local_logins_ssl=YES
force_local_data_ssl=YES
重启服务:
systemctl restart vsftpd
如果你需要的是:
可以告诉我,我可以给你对应方案。