I am trying to use nodejs (v0.8.2) with the ssh2 module to grab some files from a remote machine (using sftp). I am able to ssh to the remote machine by hand using either a password or rsa keys, but somehow the following code fails to yield a successful authentication. Any ideas about what might be going wrong?
Here is a code snippet (I've stripped out the code that does the sftp to make it easier to understand -- all I care about here is that I'm failing to authenticate.)
var express = require('express'),
fs = require('fs'),
Connection = require('ssh2');
var c = new Connection();
c.on('connect', function() {
console.log('Connection :: connect');
});
c.on('ready', function() {
console.log('Connection :: ready');
});
c.on('error', function(err) {
console.log('Connection :: error :: ' + err);
});
c.on('end', function() {
console.log('Connection :: end');
});
c.on('close', function(had_error) {
console.log('Connection :: close');
});
c.on('keyboard-interactive', function() {
console.log('Connection :: keyboard-interactive');
});
c.connect({
host: '9.xx.yy.zzz',
port: 22,
username: 'my_username_on_remote_machine',
password: 'my_password_on_remote_machine'
});
When I run this code, I get a 'Connection :: connect' response, but nothing further until the ssh times out and I get the Connection :: end and Connection :: close in rapid succession:
node testssh.js
Connection :: connect
Connection :: end
Connection :: close
Make sure to pass tryKeyboard: true, do something interesting with the prompts to the keyboard-interactive event, and call the finish callback with array holding the answers to those prompts.
c.on('keyboard-interactive', function(name, instructions, instructionsLang, prompts, finish) {
console.log('Connection :: keyboard-interactive');
finish(['my_password_on_remote_machine']);
});
c.connect({
host: '9.xx.yy.zzz',
port: 22,
username: 'my_username_on_remote_machine',
tryKeyboard: true
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With