title: php ssh2_exec not executing 'su' command
body: <p>I'm having lots of fun with ssh2 for php.(!)</p>
  
  <p>I am testing by ssh-ing into localhost (running ubuntu). I have managed to connect and authenticate with my username( not root ), and some commands (like 'ls' return some info, which is promising. Definitely getting somewhere. </p>
  
  <p>What I want to be able to do next is issue an 'su' command and then give the root password.</p>
  
  <p>I don't get an error, and a resource is returned, but there seems to be no data in the stream. (I'm kind of expecting a 'Password:' prompt). I can't authenticate directly with the root password, because that is disabled for ssh.</p>
  
  <p>Is there any reason why 'su' would return with some text, do you think?</p>
  
  <p>Should I be expecting the 'Password:' prompt back?</p>
  
  <p>Here's my code:</p>
  
  <pre><code>function changeServerPassword( $ip, $port, $sshUser, $sshPassword, $rootPassword, $newRootPassword, $newSSHPassword = false) {
          // login to server using $sshUser and $sshPassword
          // su as root and enter $rootPassword
          // if any of the above steps fail, return with appropriate error message
          if (!function_exists("ssh2_connect")) die("function ssh2_connect doesn't exist");
          // log in 
          // Do I have to make sure that port is a number?
          if(!($con = ssh2_connect($ip, $port))){
              echo "fail: unable to establish connection\n";
          } else {
              // try to authenticate with username root, password secretpassword
              if(!ssh2_auth_password($con, $sshUser, $sshPassword)) {
                  echo "fail: unable to authenticate\n";
              } else {
                  // alright, we're in!
                  echo "okay: logged in...&lt;br /&gt;";
  
                  // 
                  if (!($stream = ssh2_exec($con, "su"))) {
                      echo "fail: unable to execute command\n";
                  } else {
                      echo $stream."&lt;br /&gt;";
                      // collect returning data from command
                      stream_set_blocking($stream, true);
                      echo "after stream_set_blocking&lt;br /&gt;";
                      $data = "";
                      while ($buf = fread($stream,4096)) {
                          $data .= $buf;
                      }
                      echo "data len: " . strlen($data) . "&lt;br /&gt;";
                      echo $data."&lt;br /&gt;";
                      fclose($stream);
                  }
              }
          }
      }
  </code></pre>
  
  <p>borrowed from <a href="http://kevin.vanzonneveld.net/techblog/article/make_ssh_connections_with_php/" rel="nofollow">http://kevin.vanzonneveld.net/techblog/article/make_ssh_connections_with_php/</a>
  respect.</p>
  
  <p>The output I get is:</p>
  
  <pre><code>okay: logged in...
  Resource id #3
  after stream_set_blocking
  data len: 0
  </code></pre>
  
  <p>Thanks in advance for any help :)</p>
  
  <p>Joe</p>