1

I want execute command sudo ls -l without password prompt.

$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";
}

After execution password prompt still exists, how to avoid it ?

fedorqui
  • 275,237
  • 103
  • 548
  • 598
cetver
  • 11,279
  • 5
  • 36
  • 56

1 Answers1

0

Have you tried to add the command ls to /etc/sudoers file ? you can autorize to a user to execute some command without password.

user ALL= NOPASSWD: /bin/ls