node-ssh icon indicating copy to clipboard operation
node-ssh copied to clipboard

Error: All configured authentication methods failed

Open chenkie opened this issue 2 years ago • 10 comments

Hello!

I'm trying to test out connecting to an EC2 instance with a simple script:

const { NodeSSH } = require('node-ssh')

const ssh = new NodeSSH()

ssh.connect({
  host: 'ec<some-ip>.compute-1.amazonaws.com',
  username: 'ubuntu'
}).then(function() {
  return ssh.execCommand('cd /home/ubuntu/ && ls')
}).catch(function(err) {
  console.log('error: ', err)
})

When doing so, I get the following:

Error: All configured authentication methods failed
    at doNextAuth (/Users/me/Desktop/code/node-ssh-test/node_modules/ssh2/lib/client.js:803:21)
    at tryNextAuth (/Users/me/Desktop/code/node-ssh-test/node_modules/ssh2/lib/client.js:993:7)
    at USERAUTH_FAILURE (/Users/me/Desktop/code/node-ssh-test/node_modules/ssh2/lib/client.js:373:11)
    at 51 (/Users/me/Desktop/code/node-ssh-test/node_modules/ssh2/lib/protocol/handlers.misc.js:337:16)
    at Protocol.onPayload (/Users/me/Desktop/code/node-ssh-test/node_modules/ssh2/lib/protocol/Protocol.js:2025:10)
    at ChaChaPolyDecipherBinding.decrypt (/Users/me/Desktop/code/node-ssh-test/node_modules/ssh2/lib/protocol/crypto.js:851:26)
    at Protocol.parsePacket [as _parse] (/Users/me/Desktop/code/node-ssh-test/node_modules/ssh2/lib/protocol/Protocol.js:1994:25)
    at Protocol.parse (/Users/me/Desktop/code/node-ssh-test/node_modules/ssh2/lib/protocol/Protocol.js:293:16)
    at Socket.<anonymous> (/Users/me/Desktop/code/node-ssh-test/node_modules/ssh2/lib/client.js:713:21)
    at Socket.emit (events.js:400:28) {
  level: 'client-authentication'
}

However, I am able to ssh into this server directly:

ssh ubuntu@ec<some-ip>.compute-1.amazonaws.com

Is there anything you can recommend for what might be causing the authentication methods to fail from node-ssh?

Many thanks!

chenkie avatar Aug 05 '22 20:08 chenkie

I've also tried this on more than one local machine and server.

sonicparke avatar Aug 05 '22 20:08 sonicparke

Hello!

I do not see a password or a private key or a private key path configured in your connection parameters. When you use SSH CLI, it uses the SSH config (usually ~/.ssh/config) and/or uses the SSH agent. This does not happen implicitly in node-ssh. You have to be specific about the connection parameters.

Please specify the private key path and try again and see if it works

steelbrain avatar Aug 05 '22 20:08 steelbrain

@steelbrain Hello!

We have tried that as well. I've successfully connect manually with ssh and the key I tried in the privateKeyPath

privateKeyPath: '/Users/xxxx/.ssh/id_rsa_special_key'

I've also verified that id_rsa_special_key is added to the agent with ssh-add

I haven't tried doing anything with the ~/.ssh/config yet though

sonicparke avatar Aug 05 '22 21:08 sonicparke

OK. So after digging through this issue form ssh2 I edited /etc/ssh/sshd_config on the server and added the following line which made it connect.

PubkeyAcceptedKeyTypes=+ssh-rsa

sonicparke avatar Aug 05 '22 21:08 sonicparke

I had the same issue: All configured authentication methods failed When using SSH manually, the error returned is different: Too many authentication failures --> I think, you have perhaps too much identities loaded and the good one can't be used.

On my side, I succeeded by using SSH with the option -o 'IdentitiesOnly yes'.

Is there a way to do the same with node-ssh in case of many identities ?

Additional question, is there a way to debug the connection when using node-ssh ?

oanguenot avatar Aug 10 '22 12:08 oanguenot

Finally, found a solution on my side. SSH version used on the host is 8.9 (Ubuntu 22.04) which seems to be not compliant with #SSH2.

Both solutions described worked for me:

  • Set the PubkeyAcceptedKeyTypes to +ssh-rsa on the host
  • Or use an ed25519 key

oanguenot avatar Aug 12 '22 11:08 oanguenot

You can use the option 'debug': callbackFct to have log messages and see the version on the host

oanguenot avatar Aug 12 '22 11:08 oanguenot

Sorry, I missed your comment @sonicparke. Got the same conclusion by digging on my own :-)

oanguenot avatar Aug 12 '22 11:08 oanguenot

FWIW: I was getting this being a doofus. I had generated a new key and was passing it correctly to the config object in my Node script but hadn't added the public key to the host server yet.

rglover avatar Jan 31 '23 18:01 rglover

Adding a dependency on a newer ssh2 package, currently 1.14.0, fixed this for me.

This change seems to be done in this project's main branch, but it's not yet released.

mpartel avatar Aug 10 '23 14:08 mpartel