2012-01-14 2 views
-1

PHP에서 su 명령을 실행하려고합니다. sudo: no tty present and no askpass program specifiedPHP - 루트 명령을 실행하십시오.

감사합니다 - 내가 터미널에 명령을 넣어 또는 php /var/www/script.php로 완벽 작동하지만이 브라우저를 통해이 script.php 열 때 반환

. this에 따르면

+0

그래서 질문은 무엇인가 : 당신은 단순히 다음 코드를 사용합니다 다운로드 한 후

? 오류 메시지의 어느 부분이 선명하지 않습니까? – Jon

+0

질문은 루트로 올바르게 명령을 실행할 수있는 방법입니다. :) – user997379

답변

0

: 원격 명령을 실행할 때

SSH는 기본적으로 청각 장애를 할당하지 않습니다. tty가 없으면 sudo는 암호를 묻는 메시지를 표시 할 때 echo를 비활성화 할 수 없습니다. ssh의 "-t"옵션을 사용하여 강제로 tty를 할당 할 수 있습니다. 비밀번호가 화면에 에코되는 것을 원하지 않는다면 "visiblepw"sudoers 옵션을 사용하여이를 허용 할 수 있습니다.

0

최근 PHP가 실제 Bash 쉘을 가져 와서 상호 작용할 수있는 프로젝트를 게시했습니다. 그것을 얻으십시오 : https://github.com/merlinthemagic/MTS

당신은 루트로 진짜 bash 쉘을 얻을 수 있습니다. 그런 다음 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');