sanketbajoria / ssh2-promise

ssh with promise/async await and typescript support
https://www.npmjs.com/package/ssh2-promise
MIT License
148 stars 24 forks source link

Connection hopping: netcat processes are never killed #70

Open tkambler opened 2 years ago

tkambler commented 2 years ago

When I run the following example, I see that instances of nc (netcat) continue to run on the bastion server after the connection has been closed. If I run this example multiple times, then many instances of nc continue to run.

While this issue should be fixed, I do also see that I can avoid it entirely if I specify hoppingTool: 'native' as a config option. I was hoping you would explain why native is not the default option and what the tradeoffs are between these approaches. Thanks!

const target = {
    host: 'foo.com',
    username: 'user',
    identity: privateKeyPath,
  };

const bastion = {
  host: '127.0.0.1',
  username: 'test',
  password: 'test',
  port: 23,
};

const ssh = new SSH2Promise([bastion, target]);

await ssh.connect();

const data = await ssh.exec('whoami');
console.log(data.trim());

await ssh.close();