gpt4 book ai didi

python - Centos 7-flask 授予查看其他用户的 bash 历史记录的权限

转载 作者:太空宇宙 更新时间:2023-11-04 05:19:35 24 4
gpt4 key购买 nike

我定义了一个返回特定用户最后命令的函数。这是代码:

def user_commands(user):
line = "/home/"+user+"/.bash_history"
commands = Popen([ "tail", line], stdout=PIPE, stderr=PIPE).communicate()[0].split('\n')
return commands

但它只适用于我的用户 python

enter image description here

如果我使用其他用户,它不会显示命令列表。

enter image description here

我认为是因为它需要权限才能查看其他用户的 bash_history。如果我希望它适用于所有用户,我该怎么办。

最佳答案

这听起来像是权限问题。确保运行脚本的用户有权访问 bash 历史文件。

快速而肮脏的答案是以 root 身份运行脚本。

更好的想法可能是运行 cron 作业来收集所需的信息并将其放置在脚本可访问的目录中。

关于python - Centos 7-flask 授予查看其他用户的 bash 历史记录的权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43577993/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com