Executing Shell Commands As Different User

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
echo101
Forum Newbie
Posts: 11
Joined: Mon Jan 27, 2003 10:42 pm

Executing Shell Commands As Different User

Post 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?
shwanky
Forum Commoner
Posts: 45
Joined: Thu Feb 15, 2007 1:21 am

Post by shwanky »

Try exec("ssh user:password@hostname");
echo101
Forum Newbie
Posts: 11
Joined: Mon Jan 27, 2003 10:42 pm

Post 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:

Code: Select all

255<br />
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".
Post Reply