I am trying to connect from one linux box (machine1) to another linux box (machine2) via exec() or system() as a particular user (usr1) using ssh2.

I have...

  1. ..successfully set up and tested the ssh2 keys used to communicate from machine1 to machine2.

  2. ...successfully executed (and retrieved information) from the command line on machine1. But when I put the same command into the exec() or system() functions nothing happens.

The below example works from the shell prompt of machine1...
shell> ssh2 - l usr usr@machine2.com cat /path/to/information

But this does not work...

exec("ssh2 -l usr usr@machine2.com cat /path/to/information",$result)

while(list($info)=each($result)){
echo($info);
}

How can I tell apache or php to act as a particular user when connecting to another machine using exec() or the system() functions?

Can someone please help me? What I am doing wrong?

    Have you tried saving your command to a shell script, say "execute.sh" and running the shell script from the web?

      How would I go about doing that? I thought exec() and system() did what you are describing?

        You problem is probably above me. I had problems with using both system() and exec() for what I was trying but I got shell_exec() to work doing a simple ping, you might give that a try:

        $string = shell_exec('ping www.yahoo.com');
        echo "shell exec".$string;

        Won't work in safe mode though.

          I tried using the shell_exec() example you illustrated above and I was not able to get it to work. My brower would think and think and think, but never show any results. Thanks for the suggestion.

          Does anyone know of a way to find out what user php is using when it is executing exec(), system(), shell_exec() and passthur() functions?

            Write a Reply...