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

ssh connection fails in Mac #238

Closed
mkondath opened this issue Mar 2, 2015 · 20 comments
Closed

ssh connection fails in Mac #238

mkondath opened this issue Mar 2, 2015 · 20 comments

Comments

@mkondath
Copy link

mkondath commented Mar 2, 2015

I could connect to my Mac using command line but it fails using ssh2 Node module

ssh2adaptor ERROR : Error: Authentication failure. Available authentication methods: publickey,keyboard-interactive"", source: app://apollo/sa/components/session/ssh2-adaptor.js (79)

OSX Version10.9.4

Let me know if you need more details

Thanks

@mscdex
Copy link
Owner

mscdex commented Mar 2, 2015

Can you provide more details? Node version? ssh2 module version? Can you show the relevant code you're using?

@mkondath
Copy link
Author

mkondath commented Mar 2, 2015

Thanks for the quick response. Please see version details below
ssh2 version is 0.3.6 and I did try with the latest 0.4.4 and same result. Actually with 0.3.6 I get the 'banner' event triggered and I can see the banner displayed. see below

Node v0.11.13,
ssh2 version - 0.3.6

[49611:0302/130216:INFO:CONSOLE(49)] ""Connection :: banner _ws \n WARNING !!! READ THIS BEFORE ATTEMPTING TO LOGON !!!\n\n This System is for the use of authorized users only. Individuals using\nthis computer without authority, or in excess of their authority, are subject\nto having all of their activities on this system monitored and recorded by\nsystem personnel.\n\n In the course of monitoring individuals improperly using this system, or\nin the course of system maintenance, the activities of authorized users may\nalso be monitored. Anyone using this system expressly consents to such\nmonitoring and is advised that if such monitoring reveals possible criminal\nactivity, system personnel may provide the evidence of such monitoring to law\nenforcement officials.\n\n Cisco Acceptable Use Policy:\nhttp://wwwin.cisco.com/infosec/policies/acceptable_use.shtml\n\n"", source: app://apollo/sa/components/session/ssh2-adaptor.js (49)
[49611:0302/130216:INFO:CONSOLE(79)] "" ssh2adaptor ERROR : Error: Authentication failure. Available authentication methods: publickey,keyboard-interactive"", source: app://apollo/sa/components/session/ssh2-adaptor.js (79)
[49611:0302

see code snippet below

      var connectionProperties = {
       host: this._host, 
       port: this._port, 
       username: this._username,
       password: this._password,
       readyTimeout : 60000,
       keepaliveInterval : 600000
     };


     this._ws.on('banner', function(msg, lng) {
         console.log('Connection :: banner _ws '+msg );
       }).on('ready', function() {
          console.log('Connection :: ready _ws  Object:'+self._ws );
          console.log('connected and got new WS for SSH2 in ONOPEN ');

          self._state = 'connected';

          self._ws.shell(function(err, stream) {
              if (err) { 
                throw err;
              }
              stream.on('exit', function(code, signal) {
                  self._state = 'disconnected';

                   console.log('Stream :: exit :: code: ' + code + ', signal: ' + signal);
             }).on('close', function() {
              console.log('Stream :: close');
            }).on('data', function(data) {
              self._onWsMessage(data);
          }).stderr.on('data', function(data) {
             console.log('Device Std Err : ' + data);
          });
          self._ws.stream=stream;

        });

        return self._onOpenWs();


  }).on('error', function(err) {
      console.log('  ssh2adaptor ERROR : ' + err);
        e = err;
        self._state='disconnected';

        self._onDisconnect(1);
    }).on('debug', function(message) {
      console.log('ssh2 adaptor DEBUG : ' + message);
    }).on('close', function(hadError) {
      console.log(' ssh2 adaptor CLOSE hadError  : ' + hadError);
      self._state='disconnected';
      self._onDisconnect(1);

    }).connect(connectionProperties);

@mscdex
Copy link
Owner

mscdex commented Mar 2, 2015

Can you please try with the latest ssh2 version (v0.4.4 as of this writing)?

@mkondath
Copy link
Author

mkondath commented Mar 2, 2015

sure. I just did. now the banner event is not triggered and authentication still failed

81648:0302/134610:INFO:CONSOLE(93)] ""this._ws object after connection [object Object]"", source: app://apollo/sa/components/session/ssh2-adaptor.js (93)
[81648:0302/134610:INFO:CONSOLE(79)] "" ssh2adaptor ERROR : Error: All configured authentication methods failed"", source: app://apollo/sa/components/session/ssh2-adaptor.js (79)
[8164

@green-arrow
Copy link

Bumping this. Having the same issue when using node v0.12.0 and a privateKey property. I get "Error: All configured authentication methods failed"

@mscdex
Copy link
Owner

mscdex commented Mar 13, 2015

@green-arrow OS X also or ?

@green-arrow
Copy link

@mscdex OS X Yosemite

@mscdex
Copy link
Owner

mscdex commented Mar 15, 2015

Can both of you set debug: console.log in your connection config object and post the output in a gist/pastebin/etc?

@green-arrow
Copy link

@mscdex
Copy link
Owner

mscdex commented Mar 16, 2015

@green-arrow Ok, so you're using privateKey to authenticate but the server rejected your public key. Are you sure you have the correct public key in ~/.ssh/authorized_keys of the user you're trying to authenticate as?

@green-arrow
Copy link

@mscdex I'm fairly positive, yes. I am able to use that private key to normally ssh / scp / rsync into the server.

@mkondath
Copy link
Author

mkondath commented Mar 16, 2015 via email

@mscdex
Copy link
Owner

mscdex commented Mar 29, 2015

Ok so the problem here is that OS X (by default) does not use the "normal" password authentication mechanism, it uses the generic keyboard-interactive mechanism to display a password prompt instead.

So you can do something like this:

// ...

client.on('keyboard-interactive',
    function(name, instructions, instructionsLang, prompts, finish) {
  // Pass answers to `prompts` to `finish()`. Typically `prompts.length === 1`
  // with `prompts[0] === "Password: "`
  finish(['mypassword']);
}).on('ready', function() {
  // ...
}).connect({
  host: '192.168.100.27',
  port: 22,
  username: 'myusername',
  tryKeyboard: true // this attempts keyboard-interactive auth
});

@mscdex mscdex closed this as completed Mar 29, 2015
@mkondath
Copy link
Author

Great. That worked

Thank you

From: Brian White <notifications@github.commailto:notifications@github.com>
Reply-To: mscdex/ssh2 <reply@reply.github.commailto:reply@reply.github.com>
Date: Sunday, March 29, 2015 at 7:18 PM
To: mscdex/ssh2 <ssh2@noreply.github.commailto:ssh2@noreply.github.com>
Cc: Madhu Kondath <kmadhu@cisco.commailto:kmadhu@cisco.com>
Subject: Re: [ssh2] ssh connection fails in Mac (#238)

.on('keyboard-interactive',
function(name, instructions, instructionsLang, prompts, finish) {
// Pass answers to prompts to finish(). Typically prompts.length === 1
// and prompts[0] === "Password: "
finish(['mypassword']);
})

@mscdex
Copy link
Owner

mscdex commented Mar 30, 2015

@mkondath Thanks for the confirmation.

@green-arrow If you're still running into the problem you described, can you open a new issue as it seems unrelated to the original issue. Also if you can enable full debug output on the server-side and post that in the new issue, that would be helpful in determining what the server is seeing.

@green-arrow
Copy link

I'm actually using another library which uses ssh2, so I'll have to work it in there to verify. If I still have issues, I will open another issue.

@rockie-yang
Copy link

I had the same issue.

the tryKeyboard works for me on OSX El Capitan

Thanks very much for the solution

@Sturgelose
Copy link

Sturgelose commented Jan 20, 2017

Hi!

@mscdex I know this issue is supposed to be solved, but I got again exactly the same problem. I'm using v 0.5.4 of SSH2 in a MacOS running Sierra 10.12.2, and if I don't enable the keyboard-interacive option, it doesn't work. Could we add this as a relevant link in the documentation, or maybe review the fix?

Otherwise, the library just warns that all the authentication systems have been used and it's quite confusing the debugging! Also, tools depending on this library such as open-ssh-tunnel or electron-tunnel do not work in MacOS either!

Otherwise, thanks a lot for this amazing library!

@brandon-barker
Copy link

Hi all,

I too can confirm that this is still occurring as per @Sturgelose's comment.

Using v0.5.4 of ssh2 and on El Capitan.

The keyboard-interactive solution works perfectly for me and my use case as i'm using the library directly, but can still see this being an issue for anyone using this lib via a wrapper which perhaps doesn't handle the logging correctly or expose the connection itself so you can attach custom listeners.

Cheers and great work on this library!

@mscdex
Copy link
Owner

mscdex commented Jan 30, 2017

@Sturgelose @brandon-barker

I think this "problem" is best handled by 3rd party modules that use this module, because at this level I don't want to be making any decisions/assumptions about any keyboard-interactive prompts and how they should be handled.

macOS seems to be the most common platform that uses keyboard-interactive (only?) by default out of the box, but technically the same issue will be had with any other server that has a similar setup. The same could be said about other authentication configurations (e.g. "why can't my 2fa be automatically supported by ssh2?" or similar questions).

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