Page 1 of 1
Executing Shell Commands As Different User
Posted: Thu Feb 15, 2007 7:37 pm
by echo101
From inside a PHP script I need to be able to run a shell command under my own user account instead of under the "www" user. I just need to have the shell login to my account and then send one command before logging out. What options for doing this do I have besides modifying Apache to run under my account?
Posted: Thu Feb 15, 2007 7:47 pm
by shwanky
Try exec("ssh user:password@hostname");
Posted: Thu Feb 15, 2007 9:53 pm
by echo101
The ssh server on my machine doesn't appear to work with the user:password format because when I manually enter it in the shell it still asks me for the password on a separate line.
Here is the code I am using to test this with my personal info removed:
Code: Select all
exec('ssh USER:PASSWORD@127.0.0.1 whoami', $output, $output2);
for ($i = 0; $i < count($output); $i++){
echo("$output[$i]<br />");
}
echo("$output2<br />");
The final output for this script is just:
I have checked but my install of PHP doesn't have support for the ssh2 commands.
In a terminal window when I type in "ssh echo101:PASSWORD@127.0.0.1 whoami" it then asks "Password:" and I type in the password and it then returns "echo101".