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

Error: All configured authentication methods failed #438

Open
chenkie opened this issue Aug 5, 2022 · 10 comments
Open

Error: All configured authentication methods failed #438

chenkie opened this issue Aug 5, 2022 · 10 comments

Comments

@chenkie
Copy link

chenkie commented Aug 5, 2022

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!

@sonicparke
Copy link

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

@steelbrain
Copy link
Owner

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

@sonicparke
Copy link

@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
Copy link

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

@oanguenot
Copy link

oanguenot commented Aug 10, 2022

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
Copy link

oanguenot commented Aug 12, 2022

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
Copy link

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

@oanguenot
Copy link

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

@rglover
Copy link

rglover commented Jan 31, 2023

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.

@mpartel
Copy link

mpartel commented Aug 10, 2023

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.

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

6 participants