在Debian系统中,要实现SFTP(SSH File Transfer Protocol)的日志记录,可以通过配置SSH服务器来实现。以下是详细的步骤:
首先,需要编辑SSH服务器的配置文件 /etc/ssh/sshd_config
。
sudo nano /etc/ssh/sshd_config
在 sshd_config
文件中,找到或添加以下行来启用SFTP日志记录:
Subsystem sftp internal-sftp -l INFO
这行配置指定了SFTP子系统使用内部SFTP服务器,并设置日志级别为INFO。你可以根据需要调整日志级别,例如:
VERBOSE
:详细日志DEBUG
:调试日志接下来,配置系统日志记录以捕获SFTP日志。编辑 /etc/rsyslog.conf
或 /etc/rsyslog.d/50-default.conf
文件。
sudo nano /etc/rsyslog.conf
或者
sudo nano /etc/rsyslog.d/50-default.conf
在文件末尾添加以下行:
auth,authpriv.* /var/log/auth.log
这行配置将所有认证相关的日志(包括SFTP)记录到 /var/log/auth.log
文件中。
保存并关闭文件后,重启SSH和RSYSLOG服务以应用更改。
sudo systemctl restart sshd
sudo systemctl restart rsyslog
最后,验证SFTP日志是否正确记录。你可以查看 /var/log/auth.log
文件:
sudo tail -f /var/log/auth.log
你应该能够看到SFTP会话的详细日志信息。
以下是一个典型的SFTP日志条目示例:
Oct 1 12:34:56 hostname sshd[1234]: Accepted publickey for user from 192.168.1.100 port 56789 ssh2: RSA SHA256:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Oct 1 12:34:56 hostname sshd[1234]: pam_unix(sshd:session): session opened for user user by (uid=0)
Oct 1 12:34:56 hostname sshd[1234]: channel 0: new [client-session]
Oct 1 12:34:56 hostname sshd[1234]: channel 0: open confirm rwindow 0 rmax 2147483647
Oct 1 12:34:56 hostname sshd[1234]: channel 0: request "subsystem" accepted successfully
Oct 1 12:34:56 hostname sshd[1234]: channel 0: request "sftp-server" sent reply: success
Oct 1 12:34:56 hostname sshd[1234]: channel 0: open confirm sftp-server@openssh.com
Oct 1 12:34:56 hostname sshd[1234]: channel 0: request "chdir" sent reply: success
Oct 1 12:34:56 hostname sshd[1234]: channel 0: request "get" sent reply: success
Oct 1 12:34:56 hostname sshd[1234]: channel 0: request "close" sent reply: success
Oct 1 12:34:56 hostname sshd[1234]: channel 0: closed by remote host
Oct 1 12:34:56 hostname sshd[1234]: channel 0: free: channel 0, nchannels 1
Oct 1 12:34:56 hostname sshd[1234]: user user logged out, session 1234
Oct 1 12:34:56 hostname sshd[1234]: pam_unix(sshd:session): session closed for user user
通过以上步骤,你可以在Debian系统中成功配置SFTP日志记录。