SSH 節點出現錯誤「連線被 SSH 伺服器關閉 目前 FSM 為 Disconnect」

描述問題/錯誤/疑問

我們正在嘗試從自架的 n8n 伺服器通過 SSH 連接到路由器,但收到了此錯誤:「連線被 SSH 伺服器關閉。目前的 FSM 是 Disconnect。」我們應該檢查什麼,以及如何修正此問題?所有的 SSH 認證資訊和連線都已正確設定。

無法登入、實例無法使用),請聯絡支援團隊:help@n8n.io -->錯誤訊息是什麼(如有)?

請分享您的工作流程

(選擇畫布上的節點,並使用鍵盤快捷鍵 CMD+C/CTRL+C 和 CMD+V/CTRL+V 來複製和貼上工作流程。)
{
  "nodes": [
    {
      "parameters": {},
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        -192,
        144
      ],
      "id": "2df66140-18f8-4cfb-8e88-f3b9551038ca",
      "name": "When clicking 'Execute workflow'"
    },
    {
      "parameters": {
        "command": "display version"
      },
      "type": "n8n-nodes-base.ssh",
      "typeVersion": 1,
      "position": [
        16,
        144
      ],
      "id": "e947c9ba-d828-4490-8ad1-e5a99b5cf292",
      "name": "Execute a command",
      "alwaysOutputData": true,
      "credentials": {
        "sshPassword": {
          "name": "SSH Password account"
        }
      }
    }
  ],
  "connections": {
    "When clicking 'Execute workflow'": {
      "main": [
        [
          {
            "node": "Execute a command",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "3d1b8feb96140bbc11a6a410c27c7cb04f42940da43d0df2759b46942c8c8350"
  }
}

分享最後一個節點傳回的輸出

{
“errorMessage”: “The connection is closed by SSH Server\r\nCurrent FSM is Disconnect”,
“errorDetails”: {},
“n8nDetails”: {
“n8nVersion”: “2.18.5 (Self Hosted)”,
“binaryDataMode”: “filesystem”,
“stackTrace”: [
“Error: The connection is closed by SSH Server\r”,
“Current FSM is Disconnect”,
" at DISCONNECT (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/ssh2@1.15.0/node_modules/ssh2/lib/client.js:342:25)“,
" at 1 (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/ssh2@1.15.0/node_modules/ssh2/lib/protocol/handlers.misc.js:53:16)”,
" at Protocol.onPayload (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/ssh2@1.15.0/node_modules/ssh2/lib/protocol/Protocol.js:2059:10)“,
" at GenericDecipherNative.decrypt (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/ssh2@1.15.0/node_modules/ssh2/lib/protocol/crypto.js:1269:26)”,
" at Protocol.parsePacket [as _parse] (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/ssh2@1.15.0/node_modules/ssh2/lib/protocol/Protocol.js:2028:25)“,
" at Protocol.parse (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/ssh2@1.15.0/node_modules/ssh2/lib/protocol/Protocol.js:313:16)”,
" at Socket. (/usr/local/lib/node_modules/n8n/node_modules/.pnpm/ssh2@1.15.0/node_modules/ssh2/lib/client.js:775:21)“,
" at Socket.emit (node:events:508:28)”,
" at addChunk (node:internal/streams/readable:563:12)“,
" at readableAddChunkPushByteMode (node:internal/streams/readable:514:3)”
]
}
}

關於您的 n8n 設定的資訊

  • n8n 版本: 2.18.5
  • 資料庫(預設:SQLite): SQLite
  • n8n EXECUTIONS_PROCESS 設定(預設:own, main):
  • 通過以下方式執行 n8n(Docker、npm、n8n cloud、桌面應用): Docker
  • 作業系統:

感謝你讓我們知道這件事,我們已建立 CV-5 作為內部開發工單來進行調查。

嗨 @ibtihal 歡迎!
SSH 節點執行於 ssh2 library,它不會協商華為/Comware 風格的路由器(你的 display version 指令)仍然需要的舊版金鑰交換、密碼和主機金鑰演算法,所以路由器會斷開連線,你會看到「Current FSM is Disconnect」。該節點沒有欄位可以新增這些演算法。
改為透過跳躍主機進行路由:一個可以使用舊版演算法的小型 Linux 機器。將 SSH 節點指向該機器,並讓它使用舊選項執行路由器指令,例如:

ssh -oKexAlgorithms=+diffie-hellman-group14-sha1 -oHostKeyAlgorithms=+ssh-rsa -oCiphers=+aes128-cbc user@router-ip "display version"

參考這個:

我們已經查看了這個問題,並確認這看起来很可能是一個錯誤。它已經被轉交給我們的工程團隊之一來解決。

嗨,感謝您的說明。

能否請您澄清 n8n SSH 節點(ssh2 程式庫)支援或使用哪些特定的 SSH 金鑰交換、密碼和主機金鑰演算法?

那些是 ssh2 庫的預設值,而節點不提供 algorithms 選項來更改它們,所以這個清單正是它在網路上提供的內容。

預設提供:

kex:           curve25519-sha256, curve25519-sha256@libssh.org, ecdh-sha2-nistp256, ecdh-sha2-nistp384, ecdh-sha2-nistp521, diffie-hellman-group-exchange-sha256, diffie-hellman-group14-sha256, diffie-hellman-group15-sha512, diffie-hellman-group16-sha512, diffie-hellman-group17-sha512, diffie-hellman-group18-sha512
serverHostKey: ssh-ed25519, ecdsa-sha2-nistp256, ecdsa-sha2-nistp384, ecdsa-sha2-nistp521, rsa-sha2-512, rsa-sha2-256, ssh-rsa
cipher:        chacha20-poly1305@openssh.com, aes128-gcm, aes128-gcm@openssh.com, aes256-gcm, aes256-gcm@openssh.com, aes128-ctr, aes192-ctr, aes256-ctr
hmac:          hmac-sha2-256-etm@openssh.com, hmac-sha2-512-etm@openssh.com, hmac-sha1-etm@openssh.com, hmac-sha2-256, hmac-sha2-512, hmac-sha1

編譯到 ssh2 中但除非明確傳遞否則不提供,而節點無法做到:

kex:           diffie-hellman-group-exchange-sha1, diffie-hellman-group14-sha1, diffie-hellman-group1-sha1
serverHostKey: ssh-dss
cipher:        3des-cbc, aes256-cbc, aes192-cbc, aes128-cbc, arcfour256, arcfour128, arcfour, blowfish-cbc, cast128-cbc
hmac:          hmac-md5, hmac-sha2-256-96, hmac-sha2-512-96, hmac-ripemd160, hmac-sha1-96, hmac-md5-96

ssh-rsa 已經在預設主機金鑰清單中,所以主機金鑰不是你的路由器失敗的地方。差距在於 kex 和加密,通常在該類設備上是 diffie-hellman-group14-sha1 與 aes128-cbc 或 3des-cbc 配對。如果可以配置路由器也接受 diffie-hellman-group14-sha256 和 aes128-ctr,SSH 節點可以直接到達它,跳轉主機就不再需要。