开发者

PHP Remote Sudo Script Execution

开发者 https://www.devze.com 2023-04-08 19:06 出处:网络
I want a PHP script to cause a shell script to execute on a remote server as root. The script needs to execute sudo commands itself so it needs to be executed as root.

I want a PHP script to cause a shell script to execute on a remote server as root. The script needs to execute sudo commands itself so it needs to be executed as root.

Any Ideas?

I tried having PHP ssh login 开发者_如何学编程and execute with sudo but it was too slow.

(I have Ubuntu 10.04 & PHP5 on both servers)


SSH shouldn't be to slow unless your running many individual commands. If it is slow either the systems are under high load or you have reverse DNS problems. You could try setting UseDNS no in /etc/ssh/sshd_config and restart sshd if that makes it faster DNS is the problem.

The script needs to execute sudo commands itself so it needs to be executed as root.

Doesn't make sense if the script is running as root it doesn't need to use sudo.


I recently published a project that allows PHP to obtain and interact with a real Bash shell. Get it here: https://github.com/merlinthemagic/MTS

After downloading you would simply use the following code:

$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;
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号