在Linux上搭建SFTP时,可以通过配置SFTP服务器来启用日志记录
- 打开SSH配置文件:
sudo nano /etc/ssh/sshd_config
- 在配置文件中,找到或添加以下行以启用SFTP日志记录:
Subsystem sftp /usr/lib/openssh/sftp-server
或者,如果您使用的是OpenSSH 7.0及更高版本,可以使用以下行:
Match LocalUser your_username ChrootDirectory /path/to/your/chroot/directory ForceCommand internal-sftp AllowTcpForwarding no X11Forwarding no PermitTunnel no PasswordAuthentication yes PrintMotd no TlsRequired yes AllowUsers your_username
将your_username
替换为您的用户名,将/path/to/your/chroot/directory
替换为您要将用户限制在其中的目录路径。
-
保存并关闭配置文件。
-
重启SSH服务以应用更改:
sudo systemctl restart ssh
现在,SFTP日志记录已启用。默认情况下,日志将记录在/var/log/auth.log
文件中。要查看这些日志,您可以使用以下命令:
sudo tail -f /var/log/auth.log
这将实时显示日志中的新条目。如果您想查看特定时间段的日志,可以使用grep
和awk
等工具来过滤日志。例如,要查找与特定用户相关的日志条目,可以运行:
sudo grep 'your_username' /var/log/auth.log