加固 Linux FTP 服务器主要涉及:
减少攻击面、限制访问、加密传输、审计与监控。下面按“通用加固 → vsftpd(最常见) → Pure-FTPd / ProFTPD → 总体安全建议”的结构说明。
ftp_server --version
apt update && apt upgrade # Debian/Ubuntu
yum update # RHEL/CentOS
匿名 FTP 是主要攻击入口。
# 只允许特定 IP
iptables -A INPUT -p tcp -s 1.2.3.4 --dport 21 -j ACCEPT
iptables -A INPUT -p tcp --dport 21 -j DROP
或使用 ufw:
ufw allow from 1.2.3.4 to any port 21
明文 FTP 会泄露用户名和密码。
apt install vsftpd # Debian/Ubuntu
yum install vsftpd # CentOS/RHEL
/etc/vsftpd.conf)✅ 禁止匿名访问
anonymous_enable=NO
✅ 允许本地用户
local_enable=YES
✅ 限制用户只能在自己家目录
chroot_local_user=YES
allow_writeable_chroot=YES
✅ 禁止 root 登录
echo "root" >> /etc/ftpusers
✅ 限制可登录用户
userlist_enable=YES
userlist_file=/etc/vsftpd.userlist
userlist_deny=NO
然后:
echo "ftpuser" > /etc/vsftpd.userlist
openssl req -new -x509 -days 365 -nodes \
-out /etc/ssl/certs/vsftpd.pem \
-keyout /etc/ssl/private/vsftpd.key
ssl_enable=YES
rsa_cert_file=/etc/ssl/certs/vsftpd.pem
rsa_private_key_file=/etc/ssl/private/vsftpd.key
ssl_tlsv1=YES
ssl_sslv2=NO
ssl_sslv3=NO
force_local_data_ssl=YES
force_local_logins_ssl=YES
pasv_min_port=30000
pasv_max_port=31000
防火墙放行:
iptables -A INPUT -p tcp --dport 30000:31000 -j ACCEPT
systemctl restart vsftpd
systemctl enable vsftpd
pure-ftpd -A -E -u 1000 -B
说明:
-A:chroot 用户-E:禁止匿名-u 1000:禁止 UID < 1000 登录-B:后台运行pure-ftpd -Y 1
ServerName "Secure FTP"
DefaultRoot ~
RequireValidShell on
UserRatio off
禁止 root:
RootLogin off
chage -M 90 ftpuser
tail -f /var/log/vsftpd.log
启用详细日志:
xferlog_enable=YES
log_ftp_protocol=YES # 调试阶段
apt install fail2ban
示例过滤 SSH/FTP:
[vsftpd]
enabled = true
port = ftp,ftp-data,ftps,ftps-data
filter = vsftpd
logpath = /var/log/vsftpd.log
maxretry = 5
✅ 最安全方案
sftp user@server
✅ 必须用 FTP 时
如果你愿意,我可以:
你可以直接贴出你的 /etc/vsftpd.conf 或 Linux 发行版。