在Debian系统中,SFTP(SSH File Transfer Protocol)的日志记录可以通过配置SSH服务器来实现。以下是详细的步骤来配置Debian SFTP日志记录:
首先,你需要编辑SSH服务器的配置文件 /etc/ssh/sshd_config。
sudo nano /etc/ssh/sshd_config
在 sshd_config 文件中,找到或添加以下行来设置日志级别:
LogLevel VERBOSE
VERBOSE 级别会记录更多的详细信息,包括SFTP连接和传输的详细日志。你可以根据需要选择其他级别,如 INFO、WARN、ERROR 或 FATAL。
确保SFTP子系统已经启用。通常情况下,默认配置已经启用了SFTP子系统。如果没有,可以添加以下行:
Subsystem sftp /usr/lib/openssh/sftp-server
默认情况下,SSH日志会记录在 /var/log/auth.log 文件中。如果你想将SFTP日志记录到单独的文件中,可以使用 Syslog 或 Journalctl。
编辑 /etc/rsyslog.conf 或 /etc/rsyslog.d/50-default.conf 文件,添加以下行:
auth,authpriv.* /var/log/sftp.log
然后重启rsyslog服务:
sudo systemctl restart rsyslog
如果你使用的是 systemd,可以创建一个自定义的 journald 配置文件来记录SFTP日志。
创建一个新的配置文件 /etc/systemd/journald.conf.d/sftp.conf:
sudo nano /etc/systemd/journald.conf.d/sftp.conf
添加以下行:
[Journal]
SystemMaxUse=500M
SystemKeepFree=100M
SystemMaxFileSize=50M
SystemMaxFiles=5
然后重启 systemd-journald 服务:
sudo systemctl restart systemd-journald
最后,重启SSH服务以应用配置更改:
sudo systemctl restart sshd
你可以通过以下命令查看SFTP日志:
sudo tail -f /var/log/sftp.log
sudo journalctl -u sshd -f
通过以上步骤,你应该能够成功配置Debian系统上的SFTP日志记录。