Debian FTP服務器(以vsftpd為例)日志管理方法如下:
配置日志記錄
編輯 /etc/vsftpd.conf
,啟用日志并指定路徑:
xferlog_enable=YES
xferlog_file=/var/log/vsftpd.log
xferlog_std_format=YES
重啟服務生效:sudo systemctl restart vsftpd
。
查看日志
tail -f /var/log/vsftpd.log
less /var/log/vsftpd.log
grep 'username' /var/log/vsftpd.log
日志輪轉
編輯 /etc/logrotate.d/vsftpd
,配置按天輪轉、保留7天壓縮日志:
/var/log/vsftpd.log {
daily
rotate 7
compress
missingok
notifempty
create 640 root adm
}
手動測試:sudo logrotate -f /etc/logrotate.conf
。
監控與報警
使用 fail2ban
防止暴力破解,配置 /etc/fail2ban/jail.local
:
[vsftpd]
enabled = true
port = ftp
logpath = /var/log/vsftpd.log
maxretry = 5
bantime = 3600
重啟服務:sudo systemctl restart fail2ban
。
說明:部分舊版本或非vsftpd軟件(如ProFTPD)路徑可能不同(如 /var/log/proftpd/
),需根據實際軟件調整。