简体   繁体   中英

PHP Remote Sudo Script Execution

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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