/bin/log

Log my thoughts

Home About GitHub

23 May 2013
Execute sudo in php

It’s definitely unsecured but a quick way to do some magic.

<?php
#echo password to sudo
system('echo "PASS" | sudo -u root -S COMMAND');

#example
system('echo "password" | sudo -u root -S systemctl restart httpd.service')
?>

References:

http://www.php.net/manual/en/function.shell-exec.php#101440


Carpe diem,
JZR at 00:50

Home About GitHub