温馨提示×

debian ftpserver如何防暴破

小樊
44
2026-09-12 17:27:49
栏目: 智能运维

在 Debian 上部署 FTP 服务(常见为 vsftpdproftpd)时,防止暴力破解(Brute Force)通常从 服务配置 + 系统层防护 + 网络层限制 三方面入手。下面以最常见的 vsftpd 为例说明。


一、FTP 服务本身加固(vsftpd)

1. 限制登录尝试次数

编辑 /etc/vsftpd.conf

max_login_fails=3

2. 禁止匿名登录

anonymous_enable=NO

3. 限制可登录用户

local_enable=YES
userlist_enable=YES
userlist_deny=NO
userlist_file=/etc/vsftpd.allowed_users

然后在文件中只放允许登录的用户。

4. 使用非标准端口(可选)

listen_port=2121

5. 限制被动端口范围(方便防火墙)

pasv_min_port=30000
pasv_max_port=31000

二、使用 fail2ban 自动封 IP(强烈推荐)

1. 安装

apt update
apt install fail2ban

2. 配置 vsftpd jail

cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local

编辑 /etc/fail2ban/jail.local

[vsftpd]
enabled = true
port = ftp,ftp-data,ftps,ftps-data
filter = vsftpd
logpath = /var/log/vsftpd.log
maxretry = 3
bantime = 1h

若使用 syslog:

logpath = /var/log/auth.log

3. 启动

systemctl enable fail2ban
systemctl restart fail2ban

查看状态:

fail2ban-client status vsftpd

三、系统层防护

1. 强制使用强密码

apt install libpam-pwquality

编辑 /etc/security/pwquality.conf

minlen = 12
dcredit = -1
ucredit = -1

2. 禁用 root 登录 FTP

deny_email_enable=YES

并确保:

grep root /etc/ftpusers

四、网络层限制(防火墙)

使用 nftables / iptables

仅允许信任 IP:

iptables -A INPUT -p tcp --dport 21 -s 1.2.3.4 -j ACCEPT
iptables -A INPUT -p tcp --dport 21 -j DROP

或限制连接速率:

iptables -A INPUT -p tcp --dport 21 -m limit --limit 3/min -j ACCEPT

五、更安全的替代方案(推荐)

✅ 使用 SFTP 替代 FTP

SFTP 基于 SSH,天然防嗅探和暴破:

apt install openssh-server

限制用户:

Match User ftpuser
    ForceCommand internal-sftp
    PasswordAuthentication no

并配合:

fail2ban sshd

总结建议

最小安全组合:

  • vsftpd + fail2ban
  • 禁止匿名
  • 强密码
  • 防火墙限制

企业级建议:

  • 直接用 SFTP
  • 禁用密码登录,使用 SSH Key

如果你用的是 proftpd / pure-ftpd,或者想做 Docker 化 FTP + fail2ban,可以继续问我。

0