温馨提示×

linux sftp日志在哪看

小樊
42
2026-09-08 01:16:16
栏目: 智能运维

在 Linux 中,SFTP 日志的位置取决于你使用的 SSH/SFTP 服务实现(通常是 OpenSSH)以及系统使用的日志系统(rsyslog / journald)。下面按常见情况说明:


一、使用 OpenSSH(最常见)

1️⃣ 老版本 / 使用 rsyslog 的系统

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

2️⃣ 使用 systemd(journald)的系统

日志由 systemd 管理:

journalctl -u ssh
journalctl -u sshd

查看 SFTP 相关:

journalctl | grep sftp
journalctl -u sshd | grep sftp

二、默认 SFTP 只记录“登录”,不记录“文件操作”

⚠️ OpenSSH 默认不记录上传/下载的文件名

如果你看到的是:

Accepted password for user from x.x.x.x port xxxx ssh2

但没有文件操作日志,这是正常现象


三、如何开启 SFTP 文件操作日志(推荐做法)

方法:使用 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

如果你愿意,可以告诉我:

  • 你的 Linux 发行版
  • 是否用 Chroot
  • 是否要审计“谁下载了什么文件”

我可以给你一套可审计的 SFTP 日志方案

0