2013-02-06 90 views
1

我想执行命令sudo ls -l而没有密码提示。避免密码提示

$streams = array(
    0 => array("pipe", "r"), // stdin 
    1 => array("pipe", "w"), // stdout 
    2 => array("pipe", "w") // stderr 
); 
$process = proc_open('sudo ls -l', $streams, $pipes); 
if (is_resource($process)) { 
    list($stdin, $stdout) = $pipes; 
    fwrite($stdin, "password\n"); //must write password, but not 
    fclose($stdin); 
    var_dump(stream_get_contents($stdout)); 
    fclose($stdout); 
    $returnCode = proc_close($process); 
    echo "Return code $returnCode\n"; 
} 

执行后密码提示仍然存在,如何避免它?

+1

的可能的复制http://stackoverflow.com/questions/3166123/how-to-call-shell-script-from-php-that-requires-sudo –

+0

不幸的是没有,须藤就是例子,我需要连接到需要密码的工具 – cetver

回答

0

您是否试过将命令ls添加到/etc/sudoers文件? 你可以自动给用户执行一些没有密码的命令。

user ALL= NOPASSWD: /bin/ls