FTPServer 的配置方式取决于你使用的操作系统和 FTP 服务器软件。下面我按最常见的场景给你一个清晰、实用的配置指南,并补充安全建议。如果你能告诉我你用的是 Windows / Linux / 哪种软件,我可以给你更精确的配置。
| 系统 | 常见 FTP 服务 |
|---|---|
| Linux | vsftpd、ProFTPD、Pure-FTPd |
| Windows | FileZilla Server、IIS FTP |
| 通用 | SFTP(基于 SSH,不是 FTP) |
✅ 推荐:生产环境优先使用 SFTP(SSH) 或 FTPS(FTP over SSL),避免明文 FTP。
# Ubuntu / Debian
sudo apt update
sudo apt install vsftpd
# CentOS / Rocky / Alma
sudo yum install vsftpd
# 禁止匿名登录
anonymous_enable=NO
# 允许本地用户登录
local_enable=YES
# 允许上传
write_enable=YES
# 限制用户只能访问家目录(重要)
chroot_local_user=YES
# 允许 chroot 目录可写(新版必须)
allow_writeable_chroot=YES
# 被动模式(云服务器必开)
pasv_enable=YES
pasv_min_port=30000
pasv_max_port=31000
sudo useradd -m ftpuser
sudo passwd ftpuser
# 开放端口
sudo ufw allow 20:21/tcp
sudo ufw allow 30000:31000/tcp
✅ 云服务器:
sudo systemctl restart vsftpd
sudo systemctl enable vsftpd
ssl_enable=YES
allow_anon_ssl=NO
force_local_data_ssl=YES
force_local_logins_ssl=YES
rsa_cert_file=/etc/ssl/certs/ftp.pem
rsa_private_key_file=/etc/ssl/private/ftp.key
生成证书:
sudo openssl req -x509 -nodes -days 365 \
-keyout /etc/ssl/private/ftp.key \
-out /etc/ssl/certs/ftp.pem
| 问题 | 原因 |
|---|---|
| 能连但不能列目录 | 被动端口未放行 |
| 530 Login incorrect | 用户名/密码或 PAM 配置 |
| 425 Can’t open data connection | 防火墙 / 云安全组 |
| 无法写入 | 目录权限 |
✅ 不要使用匿名 FTP
✅ 使用 非 21 端口
✅ 使用 FTPS / SFTP
✅ 限制用户 chroot
✅ 定期更新系统
你可以直接告诉我:
我可以给你 一步一步的定制配置方案 ✅