Nasıl php kullanarak benim sunucuyu yeniden başlatmak için sudo kullanabilirim?

4 Cevap

Ben bu denedim:

<?php
  $r = shell_exec('sudo -u root -S /etc/init.d/apache2 restart < /home/$user/passfile');
  echo $rin;
?>

(Passfile parola) alamadım

<?php
  (php$output4=shell_exec('echo "$x" | whoami 1>/dev/null && sudo /etc/init.d/ssh restart');
?>
<html>
  <body>
    <script type="text/javascript">
      x=prompt("entr");
    </script>
  <body>
</html>
<html>
  <form id="form1" name="form1" method="post" action="">
    <input type="submit" name="b1" value="click"  />
  </form>
</html>
<?php
  if(isset($_POST['b1'])) {
    echo "<pre>$output4</pre>";
  }

?>

Lütfen yardım edin.

4 Cevap

Dan man sudo OS X:

-S          The -S (stdin) option causes sudo to read the password from the standard input instead of the
                   terminal device.

Sudo'yu bu şekilde çağırmak değil; o STDIN'den, (via / dev / tty) doğrudan klavyeden şifre değil okur.

Eğer bir kök kullanıcı olarak bir şey yürütmek istiyorsanız, root olarak komut dosyasını çalıştırmak zorunda.

Güvenlik nedenleriyle, sudo bu şekilde çağırmak olamaz. Bir çözüm varsa, mümkün olduğunca çabuk unutun lütfen. Ne yapmaya çalışıyorsun korkunç bir fikirdir. Bir web sayfasından sunucusunu yeniden başlatmak istemiyorum. Gerçekten yok. Evet, eminim. Aşağı klavye koyun ve yavaşça yürümek.

Yapmanız çalışıyoruz bize ne Belki biz daha iyi bir yol ile gelip yardımcı olabilir.

Tty sizin sudoers dosyası devre dışı gerektiren emin olun.

Pasaj dan / etc / sudoers

#
# Disable "ssh hostname sudo <cmd>", because it will show the password in clear.
#         You have to run "ssh -t hostname sudo <cmd>".
#
#Defaults    requiretty

# Apache suoders entry - allow passwordless login
apache ALL=(ALL) NOPASSWD: ALL