title: php shell_exec touch redirect and adduser
body: <p>I am trying to ultimately use php's <code>shell_exec</code> function to create new Linux users. I am, however, running into problems even with the debugging. Here is my code</p>
  
  <pre><code>&lt;?PHP 
  
  function adduser($username,$password,$server){ 
      try{
          //3 debug statements
          $output=shell_exec("pwd"); 
          echo $output;
         shell_exec("touch test.txt");
  
          //3 debug statements are requested by Christian
          echo '&lt;pre&gt;';
          print_r(execute('pwd'));
          print_r(execute('touch test.txt'));
  
          //actuall code
          $output=shell_exec("ssh root@$server \"adduser $username; echo $password | passwd $username --stdin\"");
      }
      catch(Exception $e){
          echo 'could not add user '.$e-&gt;getMessage();
      }
  } 
  
  $servers = array('192.168.1.8'); 
  
  foreach($servers as $server){ 
      echo $_GET['USER']."   ".$_GET['PASSWORD'];
      adduser($_GET['USER'],$_GET['PASSWORD'],$server); 
  }
  </code></pre>
  
  <p>The <code>try-catch</code> statements don't do anything, leading me to believe that shell errors are not propagated as PHP errors (Python is this way also). The line <code>$output=shell_exec("pwd")</code> returns the correct directory. The line <code>shell_exec("touch test.txt")</code>, however, fails to create th file test.txt (even if I give the full path '/home/user/.../test.txt').</p>
  
  <p>Needless to say, the actual code for adding users does not work also.</p>
  
  <p><strong>EDIT</strong> I managed to fix some of the code. The <code>touch test.txt</code> error was as a result of insufficient permissions. Apache logs in with user www-data, I simply created a home folder for that user, and made sure to touch a file in that home folder.</p>
  
  <p>The addition of the three debug statements, as per Christian's requests, are however causing problems now.</p>
  
  <p><strong>EDIT</strong> Upon further inspection, it has to do with the inability to ssh as root when logging in as user www-data. <code>ssh -v</code> returns <code>debug1: read_passphrase: can't open /dev/tty: No such device or address</code>. My guess is that ssh is asking that generic "would you like to permanently add xxx to known_hosts" but I can't respond. Is there anyway to manually add a user to the known hosts list?</p>