Board index   FAQ   Search  
Register  Login
Board index PHP PHP Scripts

Execute Shell Command and pipe the password

Links for php scripts

Moderators: macek, egami, gesf

Execute Shell Command and pipe the password

Postby deranjer » Sun Jun 03, 2012 8:48 am

I am attempting to run a command as root from a php page, is there any way to run shell_exec("su - root -c 'apt-get update'") (for example) and pass the password to the shell? Or is there another way to run a root command from php and pass the password to the command.

I would prefer not to do the follow:

edit the /etc/sudoers file;
install the ssh2 php extension;

Thanks!
deranjer
New php-forum User
New php-forum User
 
Posts: 2
Joined: Sun Jun 03, 2012 8:40 am

Re: Execute Shell Command and pipe the password

Postby Dheeraj » Mon Jun 04, 2012 9:26 pm

You can pipe password by shell command

echo <password>|sudo apt-get update
Dheeraj
New php-forum User
New php-forum User
 
Posts: 2
Joined: Mon Jun 04, 2012 9:22 pm

Re: Execute Shell Command and pipe the password

Postby deranjer » Tue Jun 05, 2012 3:52 pm

The webserver runs as www-data, so it is not in the sudoers file, and I don't want to add www-data to the /etc/sudoers file, since that can cause security issues. So running "echo password | sudo -S apt-get update" will still fail.... I need a way to pass the password to "su -root" or something similar.
deranjer
New php-forum User
New php-forum User
 
Posts: 2
Joined: Sun Jun 03, 2012 8:40 am


Return to PHP Scripts

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.