Linux SFTP日志管理实操指南
一 日志位置与快速查看
| 系统/发行版 | 默认日志文件 | 常用查看命令 |
|---|---|---|
| Debian/Ubuntu | /var/log/auth.log | `sudo tail -f /var/log/auth.log |
| RHEL/CentOS | /var/log/secure | `sudo tail -f /var/log/secure |
| 使用systemd的系统 | 通过journal | `sudo journalctl -u sshd.service -f |
| 部分系统 | /var/log/syslog | `sudo tail -f /var/log/syslog |
/var/log/下对应文件,或使用journalctl检索sshd单元日志。二 记录级别与输出目标配置
Subsystem sftp行指定日志级别与设施(facility):
Subsystem sftp internal-sftp -l INFO -f local5
Subsystem sftp /usr/libexec/openssh/sftp-server -l DEBUG3
-l为日志级别(如INFO、VERBOSE、DEBUG3),-f为syslog设施(如local5)。修改后重启SSH服务生效。LogLevel VERBOSE
三 将SFTP日志单独归集到文件
local5.* /var/log/sftp.log
sudo systemctl restart rsyslog
sudo systemctl restart sshd
sudo tail -f /var/log/sftp.log
四 日志轮转与保留策略
/var/log/secure {
daily
rotate 365
missingok
notifempty
create 0600 root root
compress
delaycompress
sharedscripts
postrotate
/bin/systemctl reload rsyslog.service >/dev/null 2>&1 || true
endscript
}
/var/log/sftp.log {
daily
rotate 365
missingok
notifempty
create 0644 root root
compress
delaycompress
sharedscripts
postrotate
/bin/systemctl reload rsyslog.service >/dev/null 2>&1 || true
endscript
}
sudo logrotate -d /etc/logrotate.d/secure
五 审计增强与安全联动
sudo auditctl -w /data/sftp -p wa -k sftp_monitor
sudo ausearch -k sftp_monitor
[sftp]
enabled = true
port = sftp
filter = sftp
logpath = /var/log/auth.log
bantime = 600
findtime = 600
maxretry = 3