Closed vella-nicholas closed 5 years ago
@vella-nicholas
You don't have to add listener for keyboard-interactive. This library internally handles it. For making connection with tryKeyboard just do as below
var SSH2Promise = require("ssh2-promise");
const connectionInfo = {
host: newValue.server_hostname,
port: 5022,
username: newValue.server_username,
tryKeyboard: true
};
var ssh = new SSH2Promise(connectionInfo);
//This will prompt for password, when ssh.connect execute. once password is entered, it can be connected or Not Connected based on password
ssh.connect().then((ssh) => {
console.log("Connected")
}, (error) => {
console.log("Not Connected")
})
Thank you for your answer.
@vella-nicholas Did it work for you? I haven't exposed keyboard-interactive event from this library. If you think, of any use case, where you would require this event, then pls let me know.
@sanketbajoria Unfortunately it did not work for me because I want to connect programmatically by supplying password
in connectionInfo
and using the keyboard-interactive
event because the server allows only keyboard-interactive authentication.. I am getting these series of errors:
DEBUG: Parser: IN_PACKETBEFORE (expecting 16)
MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 end listeners added. Use emitter.setMaxListeners() to increase limit
-> Even though it was set to 99999
'0': 'ssh',
'1': 'disconnect',
'2':
SSHConnection {
domain:
Domain {
domain: null,
_events: [Object],
_eventsCount: 1,
_maxListeners: undefined,
members: [Array] },
_events:
{ ssh: [Function: bound ],
tunnel: [Function: bound ],
'ssh:disconnect': [Function: disconnectCb],
'ssh:continue': [Function: continueCb] },
_eventsCount: 4,
_maxListeners: undefined,
activeTunnels: {},
'__$connectPromise': Promise { <pending>, domain: [Object] },
__retries: 11,
__err: { Error: Timed out while waiting for handshake
at Timeout._onTimeout (/srv/node_modules/ssh2/lib/client.js:694:19)
at ontimeout (timers.js:498:11)
at tryOnTimeout (timers.js:323:5)
at Timer.listOnTimeout (timers.js:290:5) level: 'client-timeout' },
I did not report a bug because I am not sure it is.
@sanketbajoria it would be very useful to expose "keyboard-interactive". AWS ec2 instances require a "yes" input when connecting in addition to the private key.
sshConn.addListener('keyboard-interactive', (name, instructions, instructionsLang, prompts, finish) => {
console.log('Connection :: keyboard-interactive');
finish(['yes']);
});
I would really appreciate if the event could be exposed.
It's not working for me, it does not show any password prompt. Any ideas?
public static async connect(config: ServerConfig): Promise<SSHConnection> {
const ssh2Config = {
host: config.hostName,
username: config.username,
// password: config.password,
identity: config.identityFilePath,
tryKeyboard: true
};
const ssh = new SSH2Promise.SSH(ssh2Config);
let error: Error | null;
let success: SSHConnection | undefined;
[error, success] = await to(ssh.connect());
if (error) {
console.error(colors.bgRed(colors.black(' ❌ SSH connection '+ config.connectionName +" failed \n")), error);
throw new Error();
} else {
console.log(colors.bgGreen(colors.black(' ✅ SSH connection '+ config.connectionName +' established ')));
}
return ssh;
}
❌ SSH connection production failed
Error: All configured authentication methods failed
...
at Socket.emit (node:events:390:28) {
level: 'client-authentication'
I wish to set an ssh connection and setting
tryKeyboard: true
. The problem is I am adding the listener correctly because it does not seem to work (this works correctly in the ssh2 library). Can you assist please? This is my setup: