我们有很多用户 su
使用同一个帐户,我想跟踪他们每个人运行的命令,但没有这些命令的输出。
我尝试通过管道将 su 传送到 tee
,效果很好,但它也为我提供了输出。
script
做了同样的事情。我尝试过的另一种解决方案是使用 strace,但这两者都给了我可以捕获密码的击键并且没有告诉我子 shell 中发生了什么,或者至少我无法弄清楚如何正确使用它。我也尝试了各种有趣的重定向,但所有建议的解决方案都是针对 bash 而我坚持使用 tcsh ......
我不想使用键盘记录器,因为我不想不小心捕获密码,我意识到这意味着我不知道人们在启动文本编辑器后做了什么,但我可以接受。
完美的解决方案是捕获“回声”,这是用户在点击返回时“发送”到 shell 的东西,但我没有设法提出一个足够好的问题让谷歌对此有所帮助正面。 谁能指出我正确的方向?
*考虑到我没有root权限
编辑: 不幸的是,我们的 sudo 版本是 < 1.7.4p4
最佳答案
sudo su
并不比单独的 su
好多少,但您可能想看看通过 LOG_INPUT 激活的 I/O 日志记录功能
和 sudoers(5)
手册页中的 LOG_OUTPUT
标签。
log_input
If set,
sudo
will run the command in a pseudo tty and log all user input. If the standard input is not connected to the user's tty, due to I/O redirection or because the command is part of a pipeline, that input is also captured and stored in a separate log file.Input is logged to the directory specified by the
iolog_dir
option (/var/log/sudo-io
by default) using a unique session ID that is included in the normal sudo log line, prefixed withTSID=
. Theiolog_file
option may be used to control the format of the session ID.Note that user input may contain sensitive information such as passwords (even if they are not echoed to the screen), which will be stored in the log file unencrypted. In most cases, logging the command output via log_output is all that is required.
log_output
If set,
sudo
will run the command in a pseudo tty and log all output that is sent to the screen, similar to the script(1) command. If the standard output or standard error is not connected to the user's tty, due to I/O redirection or because the command is part of a pipeline, that output is also captured and stored in separate log files.Output is logged to the directory specified by the
iolog_dir
option (/var/log/sudo-io
by default) using a unique session ID that is included in the normal sudo log line, prefixed withTSID=
. Theiolog_file
option may be used to control the format of the session ID.Output logs may be viewed with the sudoreplay(8) utility, which can also be used to list or search the available logs.
使用 visudo
修改您的 `sudoers 文件。您需要将这两个标签添加到任何向组提供权限的 sudo 条目。例如:
%admins ALL=(ALL) NOPASSWD: LOG_INPUT: LOG_OUTPUT: ALL
您还需要使用 iolog_dir
选项设置日志记录位置。例如:
Defaults iolog_dir=/var/log/sudo-io/%{user}
请注意,这至少需要 sudo 版本 1.7.4p4。
关于linux - 如何记录用户输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43063942/