php exec() 中的 sudo [英] sudo in php exec()

查看:24
本文介绍了php exec() 中的 sudo的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道这里有什么交易......

I don't know what the deal is here…

所以我想运行一个applescript:sudo osascript myscript.scpt

So I want to run an applescript: sudo osascript myscript.scpt

这在终端中运行良好,但当我通过 PHP 的 exec() 执行它时就不行了;没发生什么事.控制台说

This works fine in the terminal, but not when I execute it via PHP's exec(); nothing happens. The console says

no tty present and no askpass program specified ; TTY=unknown ; …

我做了我的研究,似乎我丢失了 sudo 命令的密码.我尝试了几种不同的方法来解决这个问题,包括:

I did my research, and it seems I'm missing the password for the sudo command. I tried a couple different ways to get around this, including:

  • /etc/sudoers
  • 中写入%admin ALL=(ALL) ALL
  • proc_open() 而不是 exec()

这些似乎都不起作用,因此让我疯狂!

none of which seem to be working, consequently driving me CrAzY!

那么基本上,有没有明确的方法让 PHP 执行一个简单的终端命令?

So basically, is there a clear-cut way to get PHP to execute a simple terminal command?

澄清一下,myscript.scpt 是一个简单的 appleScript,它改变了屏幕 UI(对于更大的项目).理论上,简单的 osascript myscript.scpt 就足够了,但是 sudo 出于某种原因需要从系统调用 some 响应.如果 sudo 可以以某种方式消除,我认为我不会遇到这个权限问题.

to clarify, myscript.scpt is a simple appleScript that changes the onscreen UI (for a larger project). In theory, simply osascript myscript.scpt should be enough, however the sudo is for some reason necessary to invoke some response from the system. If the sudo could be somehow eliminated, I don't think I would be having this permissions problem.

推荐答案

听起来您需要设置无密码 sudo.试试:

It sounds like you need to set up passwordless sudo. Try:

%admin ALL=(ALL) NOPASSWD: osascript myscript.scpt

同时注释掉以下行(在/etc/sudoers 中,通过 visudo),如果有的话:

Also comment out the following line (in /etc/sudoers via visudo), if it is there:

Defaults    requiretty

这篇关于php exec() 中的 sudo的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆