温馨提示×

linux搭建sftp有日志查看吗

小樊
119
2024-12-27 21:48:39
栏目: 智能运维
Linux服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

在Linux上搭建SFTP时,可以通过配置SFTP服务器来启用日志记录

  1. 打开SSH配置文件:
sudo nano /etc/ssh/sshd_config
  1. 在配置文件中,找到或添加以下行以启用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替换为您要将用户限制在其中的目录路径。

  1. 保存并关闭配置文件。

  2. 重启SSH服务以应用更改:

sudo systemctl restart ssh

现在,SFTP日志记录已启用。默认情况下,日志将记录在/var/log/auth.log文件中。要查看这些日志,您可以使用以下命令:

sudo tail -f /var/log/auth.log

这将实时显示日志中的新条目。如果您想查看特定时间段的日志,可以使用grepawk等工具来过滤日志。例如,要查找与特定用户相关的日志条目,可以运行:

sudo grep 'your_username' /var/log/auth.log

亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

推荐阅读:如何查看linux sftp日志

0