大网数据广告活动
服务器运维问答

Logging Chrooted SFTP user activity

· 52CE 我爱测

I have been trying to log SFTP activity by Chrooted user. I have not been able to log a single line so far for any chrooted user. For regular users it works. My current settings: /etc/ssh/sshd_config: Subsystem sftp internal-sftp…

问题原文

原帖链接 · Jeppe · CC BY-SA 3.0

I have been trying to log SFTP activity by Chrooted user.
I have not been able to log a single line so far for any chrooted user. For regular users it works.

My current settings:

/etc/ssh/sshd_config:

Subsystem sftp internal-sftp -f AUTH -l VERBOSE

ClientAliveInterval 180
PasswordAuthentication no

Match Group sftpclients
ChrootDirectory /home/sftp/%u
AllowTCPForwarding no
X11Forwarding no
ForceCommand internal-sftp -f AUTH -l VERBOSE

/etc/rsyslog.conf:

$AddUnixListenSocket        /home/sftp.log.socket
$AddUnixListenSocket        /home/sftp/dev/log.socket
$AddUnixListenSocket        /home/sftp/user1/dev/log.socket
$AddUnixListenSocket        /home/sftp/user2/dev/log.socket

:programname, isequal, "internal-sftp" -/var/log/sftp2.log
:programname, isequal, "internal-sftp" ~

/etc/rsyslog.d/sftp.conf:

 input(type="imuxsock" Socket="/home/sftp/log2.socket" CreatePath="on")
 if $programname == 'internal-sftp' then /var/log/sftp3.log

Each user has their //dev/ directory bound to /dev: mount --bind /dev /home/sftp/<user>/dev as well as the sockets defined in rsyslog.conf / sftp.conf

Question I have tried basically every suggestion I have found, what might I be missing in my setup to log chrooted users?

已采纳解答

原帖链接 · anx · CC BY-SA 3.0

Your assumption that /dev/log is a file that can be shared via bind-mounting /dev is incorrect for most modern linux distributions using systemd. Therefore, mounting your systems /dev into your chroot has little value.

$ file /dev/log
/dev/log: symbolic link to /run/systemd/journal/dev-log

Since /run is not available like that in the chroot (and should not be), sftp-server trying to write to /dev/log will consider that a broken symlink.

Instead, use input(type="imuxsock" Socket="/opt/bindmount/dev/log") to create an additional socket (which you can then bind-mount such that all chroots see it at /dev/log).

You generally should not share full /dev access to chroot anyway, the whole point of chroot is limiting attack surface.


Bonus: You can write your /etc/rsyslog.d/10-sftp.conf config like this (filter by "host name", which you can arbitrarily choose)

input(type="imuxsock" Socket="/opt/bindmount/dev/log", HostName="sftp")
if $hostname == 'sftp' then /var/log/sftp.log
&stop

This means that if you deploy other chroots, limited to other commands (such as a git-shell), you can still have all messages from chroot in the same spot, even if other programs write to /dev/log.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-10-16)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。