下面给你一套**在 Debian 上加固 vsftpd(Very Secure FTP Daemon)**的实用方案,从“最小可用 + 安全”角度出发,适用于服务器生产环境。
sudo apt update
sudo apt install vsftpd
sudo cp /etc/vsftpd.conf /etc/vsftpd.conf.bak
编辑配置文件:
sudo nano /etc/vsftpd.conf
anonymous_enable=NO
local_enable=YES
write_enable=YES
chroot_local_user=YES
allow_writeable_chroot=YES
如果不加
allow_writeable_chroot=YES,用户主目录不可写时会登录失败。
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 \
-keyout /etc/ssl/private/vsftpd.key \
-out /etc/ssl/certs/vsftpd.crt
ssl_enable=YES
allow_anon_ssl=NO
force_local_data_ssl=YES
force_local_logins_ssl=YES
rsa_cert_file=/etc/ssl/certs/vsftpd.crt
rsa_private_key_file=/etc/ssl/private/vsftpd.key
ssl_tlsv1=YES
ssl_sslv2=NO
ssl_sslv3=NO
客户端需使用 FTPS(显式 TLS)
userlist_enable=YES
userlist_file=/etc/vsftpd.userlist
userlist_deny=NO
echo ftpuser | sudo tee -a /etc/vsftpd.userlist
local_enable=YES
并只把需要 FTP 的普通用户加入 vsftpd.userlist
pasv_min_port=30000
pasv_max_port=31000
sudo ufw allow 20/tcp
sudo ufw allow 21/tcp
sudo ufw allow 30000:31000/tcp
sudo useradd -m ftpuser
sudo passwd ftpuser
sudo usermod -s /usr/sbin/nologin ftpuser
sudo apt install fail2ban
/etc/fail2ban/jail.local:
[vsftpd]
enabled = true
port = ftp
filter = vsftpd
logpath = /var/log/vsftpd.log
maxretry = 5
bantime = 3600
xferlog_enable=YES
xferlog_file=/var/log/vsftpd.log
log_ftp_protocol=YES
✅ 用 SFTP(OpenSSH)替代 FTP(更安全)
✅ 使用 虚拟用户 + PAM(隔离系统用户)
✅ 定期更新:
sudo apt update && sudo apt upgrade
sudo systemctl restart vsftpd
sudo systemctl enable vsftpd
如果你愿意,我可以:
你现在的 Debian 版本和使用场景是什么?