【发布时间】:2021-07-21 09:08:24
【问题描述】:
我正在使用 ubuntu server 20.04 LTS,我有多个 shell 文件,使用 apache 中的 php 我需要从浏览器运行多个 shell 文件,但需要以 root 身份运行。
我已经尝试了命令 shell_exec 并添加了 sudoers (www-data) 并且没有工作,我可以将其放入代码中以以 root 身份输入并能够执行 shell 脚本。
<?php
$code = shell_exec('echo "passwd" | sudo -u root -S sh /home/user/name.sh');
echo "<pre>$code</pre>";
?>
【问题讨论】:
-
不知道为什么如果 sudoers 是正确的那不起作用。我老了,但请查看
setuid。
标签: php apache root shell-exec ubuntu-20.04