在 Linux 中,SFTP 日志的位置取决于你使用的 SSH/SFTP 服务实现(通常是 OpenSSH)以及系统使用的日志系统(rsyslog / journald)。下面按常见情况说明:
SFTP 日志一般记录在:
/var/log/auth.log # Debian / Ubuntu
/var/log/secure # CentOS / RHEL / Rocky / Alma
查看 SFTP 登录和操作记录:
grep sftp /var/log/auth.log
# 或
grep sftp /var/log/secure
日志由 systemd 管理:
journalctl -u ssh
journalctl -u sshd
查看 SFTP 相关:
journalctl | grep sftp
journalctl -u sshd | grep sftp
⚠️ OpenSSH 默认不记录上传/下载的文件名
如果你看到的是:
Accepted password for user from x.x.x.x port xxxx ssh2
但没有文件操作日志,这是正常现象。
internal-sftp + 日志级别编辑 SSH 配置:
vim /etc/ssh/sshd_config
确保有以下配置:
Subsystem sftp internal-sftp -l INFO -f AUTH
或针对某个用户/组:
Match Group sftpusers
ChrootDirectory /sftp
ForceCommand internal-sftp -l INFO -f AUTH
重启 SSH:
systemctl restart sshd
然后日志中会出现类似:
open "/upload/test.txt" flags WRITE
close "/upload/test.txt"
临时开启调试(不建议长期):
LogLevel DEBUG3
查看:
journalctl -u sshd -f
| 系统 | 日志路径 |
|---|---|
| Ubuntu / Debian | /var/log/auth.log |
| CentOS / RHEL | /var/log/secure |
| systemd 系统 | journalctl -u sshd |
如果你愿意,可以告诉我:
我可以给你一套可审计的 SFTP 日志方案。