我尝试按照本教程http://www.the-art-of-web.com/system/sftp-logging-chroot/
在debian 2.5上记录chroot用户的sftp访问和操作到目前为止,我无法让它发挥作用
/etc/rsyslog.d/sftp.conf
module(load="imuxsock")
input(type="imuxsock" Socket="/var/ftp/userA/dev/log" CreatePath="on")
input(type="imuxsock" Socket="/var/ftp/userB/dev/log" CreatePath="on")
if $programname == 'internal-sftp' then /var/log/sftp.log
& stop
套接字(对于userB来说相同):
ls /var/ftp/userA/dev/ -lha
total 8.0K
drwxr-xr-x 2 root root 4.0K May 31 16:08 .
drw-r-xr-x 4 root root 4.0K May 31 12:00 ..
srw-rw-rw- 1 root root 0 May 31 16:08 log
我将日志文件放在777中以确保它不是权限问题
ls /var/log/sftp.log -lha
-rwxrwxrwx 1 root root 0 May 31 14:50 /var/log/sftp.log
的/ etc / SSH / sshd_config中
Subsystem sftp internal-sftp -l INFO -f AUTH
Match Group ftpusers
ChrootDirectory %h
ForceCommand internal-sftp -u 0002
AllowTcpForwarding no
PermitTunnel no
X11Forwarding no
然后
$sudo /etc/init.d/ssh restart
[ ok ] Restarting ssh (via systemctl): ssh.service.
$sudo /etc/init.d/rsyslog restart
[ ok ] Restarting rsyslog (via systemctl): rsyslog.service.
我在/ var / log / messages和/ var / log / syslog
中找不到任何有用的东西请帮助!!
感谢
答案 0 :(得分:1)
这显然是错误的,它永远不会成真:
if $programname == 'internal-sftp' then /var/log/sftp.log
internal-sftp
只是sshd_config
中的占位符。运行sftp服务器的实际程序仍为sshd
。
如果要区分sftp
日志,则需要使用syslog工具(-f
切换到internal-sftp
)来执行此操作,但我不确定是否支持此设置Debian(进程是在chroot中,因此您无法访问/dev/log
中的日志记录套接字。)
答案 1 :(得分:0)
注意:对于Ubuntu 18.04,截至2019年有Bug 1761630,不允许rsyslog创建自定义日志。相反,所有日志记录都转到/var/log/syslog
所以我要解决的步骤是:
/home/sftp/$DIR_CHROOT...
groupadd sftpgroup
在SSHD COnfig中,请确保使用设备LOCAL7和日志级别INFO Subsystem sftp internal-sftp -f LOCAL7 -l INFO
Match group sftpgroup
ChrootDirectory /home/sftp/$DIR_CHROOT...
X11Forwarding no
AllowTcpForwarding no
ForceCommand internal-sftp -f LOCAL7 -l INFO
sudo mkdir -p /home/sftp/$DIR_CHROOT/dev
sudo chmod 755 /home/sftp/$DIR_CHROOT/dev
sudo touch /home/sftp/$DIR_CHROOT/dev/log
# Create socket within chrooted directories to allow for logging. You could try commented options below but in ubuntu 18.04 they are useless and everything goes to `syslog`
$AddUnixListenSocket /home/sftp/$DIR_CHROOT/dev/log
# Other Folder
#$AddUnixListenSocket /home/sftp/other
# Parse the data logged at level INFO and facility LOCAL7 into /var/log/sftp.log
# LOCAL7.info /var/log/sftp.log
# Report logins and logoffs
# :syslogtag,startswith,"sftp-server" /var/log/sftp.log
sudo service ssh restart && sudo service rsyslog restart
调试
sudo service ssh status && sudo service rsyslog status
# you should see the file Operations
sudo less /var/log/syslog
sudo less /var/log/sftp.log