Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

All configured authentication methods failed #604

Closed
shishir99111 opened this issue Aug 22, 2017 · 8 comments
Closed

All configured authentication methods failed #604

shishir99111 opened this issue Aug 22, 2017 · 8 comments

Comments

@shishir99111
Copy link

shishir99111 commented Aug 22, 2017

I'm using this configuration:

function connectToSftp(sftpp, config) {
  let client = require('ssh2').Client;
  let Client = new client();

  	return new Promise((resolve, reject) => {
	    Client.on('ready', () => {
	      Client.sftp((err, sftp) => {
	        if (err) {
	          reject(err);
	        }
	        this.sftp = sftp;
	        resolve(sftp);
	      });
	    }).on('keyboard-interactive', function (name, instructions, instructionsLang, prompts, finish) {
	      console.log('Connection :: keyboard-interactive');
	      finish([config.password]);
	    }).on('error', (err) => {
	      reject(err);
	    }).connect(config);
	});
}

try{ 
	let client = require('ssh2').Client;
  	let sftp = new client();
	sftp.connect({ 
		host: '111.111.11.111', 
		port: 22, 
		username: '*********', 
		password: '*********',
	}) 
} catch(e){ 
	throw(e) 
}

giving error:

 ERROR ProcessId: 1503395610593 uncaughtException: All configured authentication methods failed 
 ERROR ProcessId: 1503395610593 Error: All configured authentication methods failed
     at tryNextAuth (/backend/node_modules/ssh2/lib/client.js:294:17)
     at SSH2Stream.onUSERAUTH_FAILURE (/backend/node_modules/ssh2/lib/client.js:473:5)
     at emitTwo (events.js:106:13)
     at SSH2Stream.emit (events.js:191:7)
     at parsePacket (/backend/node_modules/ssh2-streams/lib/ssh.js:3647:10)
     at SSH2Stream._transform (/backend/node_modules/ssh2-streams/lib/ssh.js:551:13)
     at SSH2Stream.Transform._read (_stream_transform.js:167:10)
     at SSH2Stream._read (/backend/node_modules/ssh2-streams/lib/ssh.js:212:15)
     at SSH2Stream.Transform._write (_stream_transform.js:155:12)
     at doWrite (_stream_writable.js:334:12)
     at writeOrBuffer (_stream_writable.js:320:5)
     at SSH2Stream.Writable.write (_stream_writable.js:247:11)
     at Socket.ondata (_stream_readable.js:555:20)
     at emitOne (events.js:96:13)
     at Socket.emit (events.js:188:7)
     at readableAddChunk (_stream_readable.js:176:18)
     at Socket.Readable.push (_stream_readable.js:134:10)
     at TCP.onread (net.js:548:20) 

I'm using the password based authentication rather than private key auth. Its not working in Linux server with this error. While, It is working when im trying in my MAC OS local machine
Please help

@mscdex
Copy link
Owner

mscdex commented Aug 22, 2017

Are you sure the server in question utilizes the password auth mechanism and not keyboard-interactive mode for password input? If you're not sure, then try adding tryKeyboard: true to the connection config object and add a 'keyboard-interactive' event handler that responds to (password) prompts (this is documented in the readme).

@shishir99111
Copy link
Author

@mscdex i have tried with adding tryKeyboard: true to the connection config with the keyboard-interactive event handler as mentioned in above code snipet: i.e.

.on('keyboard-interactive', function (name, instructions, instructionsLang, prompts, finish) {
	      console.log('Connection :: keyboard-interactive');
	      finish([config.password]);
	})

still, giving same error. please share if i'm missing something!

@mscdex
Copy link
Owner

mscdex commented Aug 22, 2017

At that point, if neither of those work, then either the username or password are wrong or the server uses some other method for authentication (e.g. key-based auth, etc.)

@shishir99111
Copy link
Author

Found out that the issue lies in my server outgoing sftp configuration, while i tried to access the sftp from terminal got the error as:

/etc/ssh/ssh_config: line 59: Bad configuration option: subsystem
/etc/ssh/ssh_config: line 62: Bad configuration option: chrootdirectory
/etc/ssh/ssh_config: line 63: Bad configuration option: forcecommand
/etc/ssh/ssh_config: line 64: Bad configuration option: x11forwarding
/etc/ssh/ssh_config: line 65: Bad configuration option: allowtcpforwarding
/etc/ssh/ssh_config: terminating, 5 bad configuration options

Wondering, why can't ssh2 module log this particular error.
Well, Thanks closing this issue

@mscdex
Copy link
Owner

mscdex commented Aug 22, 2017

/etc/ssh/ssh_config is for the OpenSSH client. ssh2 uses its own implementation, so it does not use that configuration file.

@pq1949
Copy link

pq1949 commented Oct 25, 2017

may be you should check the target host ssh config.
make sure the /etc/ssh/ssh_config
PasswordAuthentication is no or delete this line

@ddduarte
Copy link

ddduarte commented Dec 14, 2017

I solved using tryKeyboard = true configutation on connect and

this.ftpClient.on('keyboard-interactive', (name, instructions, instructionsLang, prompts, finish) => { finish([this.ftpConfig.connection.password]); });

@dutscher
Copy link

dutscher commented Jun 1, 2022

Here the bullet proofed code snippet:

import Client from "ssh2-sftp-client"; // "ssh2-sftp-client": "^8.1.0",
import fs from "fs";
import secrets from 'secrets.json';

const sftp = new Client();
const options = {
  host: secrets.host,
  port: secrets.port,
  username: secrets.username,
  passphrase: secrets.passphrase,
  privateKey: fs.readFileSync(secrets.privateKey),
  tryKeyboard: true,
};

sftp
  .connect(options)
  .then(() => sftp.uploadDir(src, secrets.destination))
  .then((msg: string) => {
	  console.log("Upload done:", msg);
	  return sftp.end();
  })
  .catch((err: string) => {
	  console.log(err, "catch error");
  });

sftp.on('keyboard-interactive', (name, instructions, instructionsLang, prompts, finish) => {
  finish([options.passphrase]);
});

Upload done!

Thanks @shishir99111 & @mscdex

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants