首页 > 解决方案 > 允许 Apache 在 root 中执行命令?

问题描述

我正在设置一个 bash/html CGI,它允许我在 RedHat 7.6 下使用 GnuPlot 生成图形。我的导师要求我创建一个 cgi 脚本,它能够在没有密码的情况下返回一个 sudo id (root),只使用“id”命令,而不是“sudo id”

我刚刚在我的 cgi 源代码中添加了 id 命令,以便在我的 cgi 的第一页上显示此命令的结果:

在此处输入图像描述

实际上,如果我在我的一个 cgi 脚本中添加 id 命令,则返回是:

uid=48(apache) gid=48(apache) groups=48(apache) context=system_u:system_r:httpd_sys_script_t:s0 

所以我继续 visudo 文件,并尝试在 visudo 文件的末尾添加它:

httpd ALL=(root) NOPASSWD: id

或者

apache ALL=(root) NOPASSWD: id

我的 cgi 一次又一次地返回这个:

uid=48(apache) gid=48(apache) groups=48(apache) context=system_u:system_r:httpd_sys_script_t:s0 

但我想要这个回报:

uid=0(root) gid=0(root) groups=0(root) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023

你能告诉我怎么做吗?

标签: linuxbashredhatrootvisudo

解决方案


如果您将用户名添加为第一个参数,id您将获得所需的输出。

[user@host ~]# id root
uid=0(root) gid=0(root) Gruppen=0(root)

推荐阅读