Skip to content

Instantly share code, notes, and snippets.

@64lines
Last active July 17, 2017 19:54
Show Gist options
  • Select an option

  • Save 64lines/d047d69a59ef131787981d4bceed6578 to your computer and use it in GitHub Desktop.

Select an option

Save 64lines/d047d69a59ef131787981d4bceed6578 to your computer and use it in GitHub Desktop.
[NODE][SSH] - Connection Helper index.js
var Client = require('ssh2').Client;
var conn = new Client();
conn.on('ready', function() {
console.log('Client :: ready');
conn.shell(function(err, stream) {
if (err) throw err;
stream.on('close', function() {
console.log('Stream :: close');
conn.end();
}).on('data', function(data) {
console.log('STDOUT: ' + data);
}).stderr.on('data', function(data) {
console.log('STDERR: ' + data);
});
stream.end('ls -la\nbecome avondtest\nls -l\nexit\nexit\n');
});
}).connect({
host: '192.168.100.100',
port: 22,
username: 'frylock',
privateKey: require('fs').readFileSync('/here/is/my/key')
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment