温馨提示×

FTPServer该如何配置

小樊
37
2026-08-17 14:23:17
栏目: 编程语言

FTPServer 的配置方式取决于你使用的操作系统和 FTP 服务器软件。下面我按最常见的场景给你一个清晰、实用的配置指南,并补充安全建议。如果你能告诉我你用的是 Windows / Linux / 哪种软件,我可以给你更精确的配置。


一、常见 FTPServer 类型

系统 常见 FTP 服务
Linux vsftpd、ProFTPD、Pure-FTPd
Windows FileZilla Server、IIS FTP
通用 SFTP(基于 SSH,不是 FTP)

推荐:生产环境优先使用 SFTP(SSH)FTPS(FTP over SSL),避免明文 FTP。


二、Linux 下 vsftpd(最常见)

1️⃣ 安装

# Ubuntu / Debian
sudo apt update
sudo apt install vsftpd

# CentOS / Rocky / Alma
sudo yum install vsftpd

2️⃣ 基本配置(/etc/vsftpd.conf)

# 禁止匿名登录
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

3️⃣ 创建 FTP 用户

sudo useradd -m ftpuser
sudo passwd ftpuser

4️⃣ 防火墙 & 云服务器安全组

# 开放端口
sudo ufw allow 20:21/tcp
sudo ufw allow 30000:31000/tcp

云服务器

  • 安全组放行 21 + 30000–31000

5️⃣ 启动服务

sudo systemctl restart vsftpd
sudo systemctl enable vsftpd

三、Windows 下 FileZilla Server(图形化)

1️⃣ 安装

  • 官网:https://filezilla-project.org/
  • 安装 FileZilla Server

2️⃣ 基本配置步骤

  1. 打开 FileZilla Server Interface
  2. Edit → Users
    • 添加用户
    • 设置密码
    • 指定 Home 目录
  3. Edit → Settings
    • 启用 Passive Mode
    • 设置被动端口范围
  4. 防火墙放行端口

四、FTPS(FTP over SSL)配置(推荐)

vsftpd 启用 SSL

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
✅ 定期更新系统


七、我可以继续帮你

你可以直接告诉我:

  1. ✅ 系统(Windows / Linux / 云服务器)
  2. ✅ 用的什么 FTP 软件
  3. ✅ 是否必须 FTP(还是可以用 SFTP?)
  4. ✅ 是否对外网开放

我可以给你 一步一步的定制配置方案

0