title: nodejs exec ssh hangs
body: <p>I want my nodejs app to execute a line of command and exit. The command is used for creating a remote port forwarding on a remote machine.</p>
  
  <pre><code>const exec = require("child_process").exec;
  
  let script = "ssh -i cert.pem ubuntu@ec2 -R 9000:localhost:22 -S /tmp/.ssh-ec2 -M -fN ssh-ec2";
  
  exec(script, (error, stdout, stderr) =&gt; {
        console.debug(stdout);
  });
  </code></pre>
  
  <blockquote>
    <p>node test.js</p>
  </blockquote>
  
  <p>It hangs there; but if I run pure command in terminal.</p>
  
  <blockquote>
    <p>ssh -i cert.pem ubuntu@ec2 -R 9000:localhost:22 -S /tmp/.ssh-ec2 -M -fN ssh-ec2</p>
  </blockquote>
  
  <p>It exits.</p>
  
  <p>What do I miss?</p>