-1

PHPからsuとしてコマンドを実行しようとしています。

コマンドをターミナルに配置するか、php /var/www/script.phpそれを使用すると完全に機能しますが、ブラウザからscript.phpを開くと、次のように返されます-sudo: no tty present and no askpass program specified

ありがとう。

4

2 に答える 2

0

私は最近、PHP が実際の Bash シェルを取得して対話できるようにするプロジェクトを公開しました。ここから入手してください: https://github.com/merlinthemagic/MTS

root として実際の 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');
于 2016-05-20T09:48:56.070 に答える
0

これによると:

ssh は、リモート コマンドの実行時にデフォルトで tty を割り当てません。tty がないと、sudo はパスワードの入力を求めるときにエコーを無効にできません。ssh の「-t」オプションを使用して、強制的に tty を割り当てることができます。または、パスワードが画面にエコーされても構わない場合は、「visiblepw」sudoers オプションを使用してこれを許可できます。

于 2012-01-14T15:28:08.110 に答える