我試圖從php執行一個命令su。PHP - 以root身份執行命令
當我把命令終端或php /var/www/script.php
它可以完美運行,但是當我通過瀏覽器打開的script.php,則返回 - sudo: no tty present and no askpass program specified
感謝。
我試圖從php執行一個命令su。PHP - 以root身份執行命令
當我把命令終端或php /var/www/script.php
它可以完美運行,但是當我通過瀏覽器打開的script.php,則返回 - sudo: no tty present and no askpass program specified
感謝。
根據this:運行遠程命令時
SSH不分配默認一個tty。 沒有tty,sudo在提示輸入密碼時無法禁用回顯。 你可以使用ssh的「-t」選項強制它分配一個tty。 或者,如果您不介意將密碼回顯至 屏幕,則可以使用「visiblepw」sudoers選項來允許此操作。
我最近發佈了一個項目,該項目允許PHP獲取真實的Bash shell並與之交互。在此處獲取:https://github.com/merlinthemagic/MTS
您可以以root身份獲得真正的bash shell。然後你可以觸發你的PHP腳本或直接在bash中執行命令。
下載您只需使用下面的代碼後:
$shell = \MTS\Factories::getDevices()->getLocalHost()->getShell('bash', true);
$return1 = $shell->exeCmd('yourFirstCommand');
$return2 = $shell->exeCmd('yourSecondCommand');
//the return will be a string containing the return of the script
echo $return1;
echo $return2;
//or if you want to trigger your script as root
$return3 = $shell->exeCmd('php /my/script.php');
echo $return3;
//If your script contains code to make an SSH connection to another server
//there is a much easier way to do that using the project:
$shell = \MTS\Factories::getDevices()->getRemoteHost('ip_address')->getShellBySsh('username', 'secretPassword');
那麼,什麼是問題?哪部分錯誤信息不清楚? – Jon 2012-01-14 15:24:55
問題是我如何以root身份正確執行命令:) – user997379 2012-01-14 15:29:37