允许Apache以root身份执行命令?

时间:2019-05-27 08:14:21

标签: linux bash redhat root visudo

我正在设置一个bash / html CGI,它将允许我在RedHat 7.6下使用GnuPlot生成图形。 我的老师要求我创建一个cgi脚本,该脚本无需密码即可返回sudo id(root),仅使用“ id”命令,而不是“ sudo id”即可。

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

enter image description here

实际上,如果我在我的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

你能告诉我怎么做吗?

1 个答案:

答案 0 :(得分:0)

如果将用户名作为第一个参数添加到id,则会得到所需的输出。

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