我正在尝试从PHP中获得一个sudo命令来执行。为了简单起见,我使用了包装在预标记中的passthru。长话短说,我想要一些进出口统计。
我在一个CentOS盒子里。
在登录via 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辅助“或"dir”,这样就可以很好地工作。请帮帮忙。
可能重复:How to call shell script from php that requires SUDO?
注意:我可以通过命令行运行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不过,这样走就行了吗?
发布于 2014-04-04 18:33:53
编辑您的/etc/sudoers文件并删除关于默认请求的行。
**更新--我猜默认情况下启用了该选项--因此,请添加如下内容:
Defaults:myuser !requirettyhttps://stackoverflow.com/questions/22869980
复制相似问题