我正在使用節點來管理我們的一些思科設備,並遇到了我在過去兩天無法解決的問題。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
Thanks mscdex。我會去做。 – Pankaj