2016-08-22 25 views
0

我正在使用節點來管理我們的一些思科設備,並遇到了我在過去兩天無法解決的問題。node.js ssh2shell包裝無法登錄到思科設備

使用SSH2模塊我可以在Cisco設備上連接和執行命令,但這限制了我一次只能運行一個命令。對於後續命令,它需要我建立一個新的連接,然後運行另一個命令。這不適合我的需求。

閱讀一些在SO中的答案我開始使用SSH2Shell封裝SSH2,因爲它允許多個命令按順序執行。但是使用SSH2Shell,我無法建立到思科設備的連接,因爲客戶端提供的密碼與服務器上支持的密碼不匹配。我對SSH2模塊有同樣的問題,但我可以通過添加密碼和KEX來解決這個問題。當我在SSh2Shell中執行相同的操作時不起作用。我試圖用幾種不同的方式和不同的地方添加它們,但它們不會連接。

我想我在正確的軌道上,我只是不知道添加密碼和KEX的正確位置。

這裏是我的SSH2Shell代碼:

var host = { 
    server:  { 
      host:   "<host IP>", 
      port:   "22", 
      userName:  "<username>", 
      password: "<password>" 
     }, 
     connection:   require ('ssh2'), 
     commands:  [ 
      "show version", 
      "show ssh" 
     ], 
     algorithms: { 
      kex: [ 
       'diffie-hellman-group1-sha1', 
       'ecdh-sha2-nistp256', 
       'ecdh-sha2-nistp384', 
       'ecdh-sha2-nistp521', 
       'diffie-hellman-group-exchange-sha256', 
       'diffie-hellman-group14-sha1'], 
      cipher: [ 
       'aes128-ctr', 
       'aes192-ctr', 
       'aes256-ctr', 
       'aes128-gcm', 
       '[email protected]', 
       'aes256-gcm', 
       '[email protected]', 
       'aes256-cbc' 
      ] 
     }, 
     msg: { 
      send: function(message) { 
      console.log("message: " + message); 
      } 
     }, 
    verbose: true, 
    debug:    true, 
    idleTimeOut:   15000, 
    connectedMessage: "connected", 
    readyMessage:  "ready", 
    closedMessage:  "closed", 

    onCommandComplete: function(command, response, sshObj) { 

     console.log("------------- onCommandComplete ---------"); 
     console.log(command + ": " + response); 
    }, 
    onEnd: function(sessionText, sshObj) { 
     console.log("--------- onEnd has ------------"); 
     console.log(sessionText); 
    } 
}; 



//Create a new instance 
var SSH2Shell = require ('ssh2shell'), 
    SSH  = new SSH2Shell(host); 

//Start the process 
SSH.connect(); 

其次是在終端上「封閉」當我執行此我得到「連接」。在Cisco路由器上進行調試顯示我的密碼不匹配。

Aug 22 12:06:59:%SSH-3-NO_MATCH:找不到匹配的密碼:客戶端aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm,aes128-gcm @ openssh.com,aes256 -gcm,AES256-GCM @ openssh.com服務器AES128-CBC,3DES-CBC,AES192-CBC,AES256-CBC

回答

0

我在Github上爲SSH2Shell記錄了一個問題,感謝作者「cmp-202」現在已解決此問題。以下是提供密碼和KEX的腳本的副本。 在SSH2Shell版本1.5.1中發現並解決了另一個問題,其中現在實現了「鍵盤交互」事件。下面的腳本同時使用了用戶定義的密碼和「鍵盤交互」事件:

var host = { 
    server: { 
     host: "<hostname or IP>", 
     port: "22", 
     userName: "<username>", 
     password: "<password>", 
     hashMethod:  "md5", 
     readyTimeout: 50000, 
     tryKeyboard: true, 
     algorithms: { 
     kex: [ 
      'diffie-hellman-group1-sha1', 
      'ecdh-sha2-nistp256', 
      'ecdh-sha2-nistp384', 
      'ecdh-sha2-nistp521', 
      'diffie-hellman-group-exchange-sha256', 
      'diffie-hellman-group14-sha1'], 
     cipher: [ 
      'aes128-ctr', 
      'aes192-ctr', 
      'aes256-ctr', 
      'aes128-gcm', 
      '[email protected]', 
      'aes256-gcm', 
      '[email protected]', 
      'aes256-cbc' ] 
     } 
     }, 
     commands: [ 
     "show deviceport global", 
     "show deviceport names" ], 
     msg: { 
     send: function(message) { 
      console.log("message: " + message); 
     } 
     }, 
     verbose: true, 
     debug: true, 
     idleTimeOut: 10000, 
     ["keyboard-interactive"]: function(name, instructions, instructionsLang, prompts, finish){ 
     console.log('Connection :: keyboard-interactive'); 
     console.log(prompts); 
     finish(["<password>"]); 
     }, 
     onEnd: function(sessionText, sshObj) { 
     sshObj.msg.send("--------- onEnd has ------------"); 
     sshObj.msg.send(sessionText); 
     } 

}; 

//Create a new instance 
var SSH2Shell = require ('ssh2shell-ssh2.connect-options'), 
SSH = new SSH2Shell(host); 

//Start the process 
SSH.connect(); 

希望這會爲某人節省一些時間。

0

ssh2shell模塊似乎只能通過特定的選項ssh2,所以不會通過algorithms選項通過。您可能希望向項目的問題跟蹤器提交問題。

+0

Thanks mscdex。我會去做。 – Pankaj