Is there a way to execute commands under a different username, ie. log on to the computer under userx with passx and execute commandx?
logging in?
anyone else going "huh"
how bout some specifics, are you trying to do this with php
what do you want to run, are you at the right forum, etc...
hehehe, sure
ok I'm making an application that checks and is able to edit various files on the sever's harddrive for configuration purposes. Some of these files (like /etc/sysconfig/iptables and /etc/hosts) are only accessible and writable to root, so I'm looking for a way to utilize either the backticks or shell_exec() to login as root (or other high privladged user) to view and edit these files. Ideally I would like to execute su, enter an password, and then have an open shell. I run linux by the way with php as an apache module.
my first instinct was to use 'sudo' or 'su' when using the shell_exec() function. But I know that 'sudo' prompts for a password so that you can get super user access.
I was searching the 'sudo' command and hoping there is an option to give the password so you don't get that prompt, but i didn't find any
this is what i thought it might look like:
shell_exec("sudo -p password; vim /etc/dir/file");
at least something like that.... dunno.
I don't have much experience using the cmd(), exec(), shell_exec() commands, but i thought i'd share what i had in mind. It might give you an idea at least.
ohh... i just thought about this. you can upload (ftp) the file; move it to its desired destination and override the original file and then give it the correct permissions.
ex:
cmd("sudo -p password; mv /home/user/upload/hosts /etc/hosts; chmod 222 /etc/hosts; chown root:root /etc/hosts")
or ahhhh i will stop
I know this thread is pretty old, but there is a way to set up sudo so it doesn't prompt for a password.
You can add the NOPASSWD keyword before the relevant command to the sudoers file.
Example
I've used the following to allow the httpd user to use the ping command without prompting for a password:
httpd ALL=NOPASSWD: /bin/ping