繁体   English   中英

PHP Exec Sudo / Exim命令

[英]PHP Exec Sudo/Exim commands

我正在尝试从PHP内部执行sudo命令。 为了简单起见,我使用包装在预标签中的passthru。 长话短说,我想获得一些进出口数据。

我在CentOS盒子上。

通过shell登录后,我通过visudo添加了以下行。

myuser      ALL = NOPASSWD: /usr/sbin/exiwhat

装入外壳时,可以使用以下两个命令之一成功执行exiwhat命令。

sudo -u myuser -H /usr/sbin/exiwhat
sudo -u myuser -H exiwhat

我什至尝试通过su成为用户,但仍然成功。

su myuser
sudo /usr/sbin/exiwhat
-or-
sudo exiwhat

我的PHP脚本看起来有点像这样。

<?php
echo '<pre>';
passthru('whoami');
echo "\n1)";
passthru('sudo exiwhat');
echo "\n2)";
passthru('sudo /usr/sbin/exiwhat');
echo "\n3)";
passthru('exiwhat');
echo "\n4)";
passthru('/usr/sbin/exiwhat');
echo "\n";
echo '</pre>';

我得到的是:

myuser

1)
2)
3)
4)No exim process data

我已经尝试过

exec('exiwhat',$output);

但是输出返回为空数组。

我可以使“ ps aux”或“ dir”之类的简单内容正常工作。 请帮忙。

可能重复: 如何从需要SUDO的php调用shell脚本?

注意:我可以通过命令行运行exiwhat并获得大量输出。 在任何时间点,我们都有几百封电子邮件。

更新:在另一个线程中,我向每个命令添加了“ 2>&1”,并获得了以下内容

myuser

1)sudo: sorry, you must have a tty to run sudo

2)sudo: sorry, you must have a tty to run sudo

3)sh: exiwhat: command not found

4)/bin/rm: cannot remove `/var/spool/exim/exim-process.info': Permission denied
exim(770): Operation not permitted
exim(8016): Operation not permitted
exim(15618): Operation not permitted
exim(15626): Operation not permitted
exim(16751): Operation not permitted
exim(16765): Operation not permitted
exim(32207): Operation not permitted
exim: no process killed
No exim process data

更新:我通过visudo添加了以下行,我的sudo命令现在可以正常工作

Defaults:myuser !requiretty

那是那样省钱吗?

编辑您的/ etc / sudoers文件,并删除有关Default requiretty的行。

**更新,我猜默认情况下会启用此选项,因此请添加以下内容:

Defaults:myuser        !requiretty

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM