简体   繁体   English

通过PHP的Bash脚本(apache2)

[英]Bash script via php (apache2)

Bonsoir, I have a bash script that run normally on terminal but when I run it via php, it runs some commands(thoses that not have sudo). Bonsoir,我有一个可以在终端上正常运行的bash脚本,但是当我通过php运行它时,它会运行一些命令(没有sudo的命令)。 This is my file sudoers where i give the rights to www-data : 这是我的文件Sudoers,在其中我授予www-data的权利:

# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL
www-data ALL=(ALL:ALL) NOPASSWD:ALL

And this error that i get when i type sudo service apache2 status : 而当我输入sudo service apache2 status时遇到的此错误:

juin 01 21:33:13 les-tatates-cm sudo[21697]: pam_unix(sudo:auth): auth could not identify password for [www-data]

How to fix it ? 如何解决? Need help please ! 请需要帮助!

You can do something like this : 您可以执行以下操作:

<?php
include('Net/SSH2.php');

$ssh = new Net_SSH2('www.domain.tld');
$ssh->login('username', 'password');

$ssh->read('[prompt]');
$ssh->write("sudo command\n");
$ssh->read('Password:');
$ssh->write("Password\n");
echo $ssh->read('[prompt]');
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM