PHP shell_exec() 和 sudo:必须是 setuid root

发布于 2024-08-20 14:55:19 字数 303 浏览 1 评论 0原文

我有一个 shell_exec() 命令来访问文档根目录上方的目录,因此我需要使用 sudo “作为 root”来实现它。 (我了解安全问题并正在采取措施解决它)。

问题是当我运行 shell_exec() 时,我的 apache error_log 文件中出现“sudo:必须是 setuid root”错误。

我认为解决方案是 chmod 4750 由我的 sheel_exec() 调用的 bash 脚本,但这并不能完成任务。

“sudo:必须是 setuid root”到底是什么试图告诉我,我该如何解决它?

I have a shell_exec() command that accesses a directory above my document root so I need to use sudo "as root" to make it happen. (I understand the security issues and am putitng in measures to address it).

The issue is when I run the shell_exec() I get a "sudo: must be setuid root" error in my apache error_log file.

I thought the solution was to chmod 4750 the bash script that is called by my sheel_exec() but that does not do the job.

What exactly is "sudo: must be setuid root" trying to tell me and how might I resolve it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

給妳壹絲溫柔 2024-08-27 14:55:19

sudo 可执行文件本身是否 setuid root?您可能需要

chown root: /usr/bin/sudo
chmod u+s /usr/bin/sudo

Is the sudo executable itself setuid root? You may need to

chown root: /usr/bin/sudo
chmod u+s /usr/bin/sudo
最冷一天 2024-08-27 14:55:19

或者,完全跳过 sudo。如果您的脚本由 root 用户拥有并设置了自己的 setuid 位,那么您不需要使用 sudo 来获取 root 权限。事实上,这样会更安全;您保证您的网络用户只能使用该脚本,而无需编辑 sudoers。为此,请从 shell_exec()删除 sudo:

<?php
    shell_exec('/path/to/your/command');
?>

Alternatively, skip sudo altogether. If your script is owned by root and has its own setuid bit set, then you don't need to use sudo to get root privileges. In fact, it can be more secure that way; you guarantee that your web user can only use that script, without having to edit sudoers. To do so, remove sudo from your shell_exec() line:

<?php
    shell_exec('/path/to/your/command');
?>
呆° 2024-08-27 14:55:19

你检查过你的脚本的权限吗?

谁拥有该脚本?

Web用户是否有sudo的权限?

Did you check the permissions for your script?

Who is owning the script?

Does the web user has the rights to sudo?

南七夏 2024-08-27 14:55:19

要解决此问题,您需要以 root 身份 chown 和 chmod sudo 文件,如下所示。

chown root:root /usr/bin/sudo
chmod 4111 /usr/bin/sudo
chmod 0440 /etc/sudoers

To fix this problem you need to chown and chmod sudo file as root as below.

chown root:root /usr/bin/sudo
chmod 4111 /usr/bin/sudo
chmod 0440 /etc/sudoers
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文