title: ssh2 timed out while waiting for handshake
body: <p>I am trying to use node.js to issue command line in my Linux servers via ssh. I found this <a href="https://github.com/mscdex/ssh2" rel="nofollow">https://github.com/mscdex/ssh2</a> and tried to test out. Here is my code and <code>ready</code> event is never fired:</p>
  
  <pre><code> var Client = require('ssh2').Client;
  
   console.log('Start ssh2...');
   var conn = new Client();
   conn.on('ready', function() {
      console.log('Client :: ready');
              conn.shell(function(err, stream) {
                if (err) throw err;
                stream.on('close', function() {
                  console.log('Stream :: close');
                  conn.end();
                }).on('data', function(data) {
                  console.log('STDOUT: ' + data);
                }).stderr.on('data', function(data) {
                  console.log('STDERR: ' + data);
                });
                stream.end('ls -l\nexit\n');
              });
   }).connect({
     host: '12.12.12.12',
     port: 22,
     tryKeyboard: true,
     debug: console.log,
     readyTimeout: 99999,
     username: 'root',
     password: 'password'
   });
  </code></pre>
  
  <p>I did set long <code>readyTimeout</code> and <code>tryKeyboard</code> true.</p>
  
  <p>Here is the log:</p>
  
  <pre><code>DEBUG: Local ident: 'SSH-2.0-ssh2js0.0.14'
  DEBUG: Client: Trying 123.123.123.123 on port 22 ...
  DEBUG: Client: Connected
  DEBUG: Parser: IN_INIT
  DEBUG: Parser: IN_GREETING
  DEBUG: Parser: IN_HEADER
  DEBUG: Remote ident: 'SSH-2.0-OpenSSH_6.2'
  DEBUG: Outgoing: Writing KEXINIT
  DEBUG: Parser: IN_PACKETBEFORE (expecting 8)
  DEBUG: Parser: IN_PACKET
  DEBUG: Parser: pktLen:1540,padLen:7,remainLen:1536
  DEBUG: Parser: IN_PACKETDATA
  DEBUG: Parser: IN_PACKETDATAAFTER, packet: KEXINIT
  DEBUG: Comparing KEXINITs ...
  DEBUG: (local) KEX algorithms: diffie-hellman-group-exchange-sha256,diffie-hellm
  an-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
  DEBUG: (remote) KEX algorithms: ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-
  nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1
  ,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
  DEBUG: KEX algorithm: diffie-hellman-group-exchange-sha256
  DEBUG: (local) Host key formats: ssh-rsa,ssh-dss
  DEBUG: (remote) Host key formats: ssh-rsa,ssh-dss,ecdsa-sha2-nistp256
  DEBUG: Host key format: ssh-rsa
  DEBUG: (local) Client-&gt;Server ciphers: aes256-ctr,aes192-ctr,aes128-ctr,aes128-g
  cm,aes128-gcm@openssh.com,aes256-gcm,aes256-gcm@openssh.com,aes256-cbc,aes192-cb
  c,aes128-cbc,blowfish-cbc,3des-cbc,arcfour256,arcfour128,cast128-cbc,arcfour
  DEBUG: (remote) Client-&gt;Server ciphers: aes128-ctr,aes192-ctr,aes256-ctr,arcfour
  256,arcfour128,aes128-gcm@openssh.com,aes256-gcm@openssh.com,aes128-cbc,3des-cbc
  ,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu
  .se
  DEBUG: Client-&gt;Server Cipher: aes256-ctr
  DEBUG: (local) Server-&gt;Client ciphers: aes256-ctr,aes192-ctr,aes128-ctr,aes128-g
  cm,aes128-gcm@openssh.com,aes256-gcm,aes256-gcm@openssh.com,aes256-cbc,aes192-cb
  c,aes128-cbc,blowfish-cbc,3des-cbc,arcfour256,arcfour128,cast128-cbc,arcfour
  DEBUG: (remote) Server-&gt;Client ciphers: aes128-ctr,aes192-ctr,aes256-ctr,arcfour
  256,arcfour128,aes128-gcm@openssh.com,aes256-gcm@openssh.com,aes128-cbc,3des-cbc
  ,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu
  .se
  DEBUG: Server-&gt;Client Cipher: aes256-ctr
  DEBUG: (local) Client-&gt;Server HMAC algorithms: hmac-md5,hmac-sha1,hmac-sha2-256,
  hmac-sha2-256-96,hmac-sha2-512,hmac-sha2-512-96,hmac-ripemd160,hmac-sha1-96,hmac
  -md5-96
  DEBUG: (remote) Client-&gt;Server HMAC algorithms: hmac-md5-etm@openssh.com,hmac-sh
  a1-etm@openssh.com,umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-25
  6-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-ripemd160-etm@openssh.com,h
  mac-sha1-96-etm@openssh.com,hmac-md5-96-etm@openssh.com,hmac-md5,hmac-sha1,umac-
  64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-ripemd160,h
  mac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
  DEBUG: Client-&gt;Server HMAC algorithm: hmac-md5
  DEBUG: (local) Server-&gt;Client HMAC algorithms: hmac-md5,hmac-sha1,hmac-sha2-256,
  hmac-sha2-256-96,hmac-sha2-512,hmac-sha2-512-96,hmac-ripemd160,hmac-sha1-96,hmac
  -md5-96
  DEBUG: (remote) Server-&gt;Client HMAC algorithms: hmac-md5-etm@openssh.com,hmac-sh
  a1-etm@openssh.com,umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-25
  6-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-ripemd160-etm@openssh.com,h
  mac-sha1-96-etm@openssh.com,hmac-md5-96-etm@openssh.com,hmac-md5,hmac-sha1,umac-
  64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-ripemd160,h
  mac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
  DEBUG: Server-&gt;Client HMAC algorithm: hmac-md5
  DEBUG: (local) Client-&gt;Server compression algorithms: none
  DEBUG: (remote) Client-&gt;Server compression algorithms: none,zlib@openssh.com
  DEBUG: Client-&gt;Server compression algorithm: none
  DEBUG: (local) Server-&gt;Client compression algorithms: none
  DEBUG: (remote) Server-&gt;Client compression algorithms: none,zlib@openssh.com
  DEBUG: Server-&gt;Client compression algorithm: none
  DEBUG: Outgoing: Writing KEXDH_GEX_REQUEST
  DEBUG: Parser: IN_PACKETBEFORE (expecting 8)
  DEBUG: Parser: IN_PACKET
  DEBUG: Parser: pktLen:404,padLen:8,remainLen:400
  DEBUG: Parser: IN_PACKETDATA
  DEBUG: Parser: IN_PACKETDATAAFTER, packet: KEXDH_GEX_GROUP
  DEBUG: Outgoing: Writing KEXDH_GEX_INIT
  DEBUG: Parser: IN_PACKETBEFORE (expecting 8)
  DEBUG: Parser: IN_PACKET
  DEBUG: Parser: pktLen:956,padLen:7,remainLen:952
  DEBUG: Parser: IN_PACKETDATA
  DEBUG: Parser: IN_PACKETDATAAFTER, packet: KEXDH_GEX_REPLY
  DEBUG: Checking host key format
  DEBUG: Checking signature format
  DEBUG: Verifying host fingerprint
  DEBUG: Host accepted by default (no verification)
  DEBUG: Verifying signature
  DEBUG: Outgoing: Writing NEWKEYS
  DEBUG: Parser: IN_PACKETBEFORE (expecting 8)
  DEBUG: Parser: IN_PACKET
  DEBUG: Parser: pktLen:12,padLen:10,remainLen:8
  DEBUG: Parser: IN_PACKETDATA
  DEBUG: Parser: IN_PACKETDATAAFTER, packet: NEWKEYS
  DEBUG: Outgoing: Writing SERVICE_REQUEST (ssh-userauth)
  DEBUG: Parser: IN_PACKETBEFORE (expecting 16)
  DEBUG: Parser: IN_PACKET
  DEBUG: Parser: Decrypting
  DEBUG: Parser: pktLen:28,padLen:10,remainLen:16
  DEBUG: Parser: IN_PACKETDATA
  DEBUG: Parser: Decrypting
  DEBUG: Parser: HMAC size:16
  DEBUG: Parser: IN_PACKETDATAVERIFY
  DEBUG: Parser: Verifying MAC
  DEBUG: Parser: IN_PACKETDATAVERIFY (Valid HMAC)
  DEBUG: Parser: IN_PACKETDATAAFTER, packet: SERVICE_ACCEPT
  DEBUG: Outgoing: Writing USERAUTH_REQUEST (password)
  DEBUG: Parser: IN_PACKETBEFORE (expecting 16)
  DEBUG: Parser: IN_PACKET
  DEBUG: Parser: Decrypting
  DEBUG: Parser: pktLen:44,padLen:7,remainLen:32
  DEBUG: Parser: IN_PACKETDATA
  DEBUG: Parser: Decrypting
  DEBUG: Parser: HMAC size:16
  DEBUG: Parser: IN_PACKETDATAVERIFY
  DEBUG: Parser: Verifying MAC
  DEBUG: Parser: IN_PACKETDATAVERIFY (Valid HMAC)
  DEBUG: Parser: IN_PACKETDATAAFTER, packet: USERAUTH_FAILURE
  DEBUG: Client: password auth failed
  DEBUG: Outgoing: Writing USERAUTH_REQUEST (keyboard-interactive)
  DEBUG: Parser: IN_PACKETBEFORE (expecting 16)
  DEBUG: Parser: IN_PACKET
  DEBUG: Parser: Decrypting
  DEBUG: Parser: pktLen:44,padLen:11,remainLen:32
  DEBUG: Parser: IN_PACKETDATA
  DEBUG: Parser: Decrypting
  DEBUG: Parser: HMAC size:16
  DEBUG: Parser: IN_PACKETDATAVERIFY
  DEBUG: Parser: Verifying MAC
  DEBUG: Parser: IN_PACKETDATAVERIFY (Valid HMAC)
  DEBUG: Parser: IN_PACKETDATAAFTER, packet: USERAUTH_INFO_REQUEST
  DEBUG: Parser: IN_PACKETBEFORE (expecting 16)
  events.js:85
        throw er; // Unhandled 'error' event
              ^
  Error: Timed out while waiting for handshake
      at null._onTimeout (\node_modules\ssh2\lib\client.js:138:17)
      at Timer.listOnTimeout (timers.js:110:15)
  </code></pre>
  
  <p>However, if I change ssh server configuration to have private key in my node.js server, it could authenticate. My question is <strong>why username/password authentication doesn't work and how to fix it (either my code or change server configs somehow)?</strong></p>