4

【茶包射手日記】SSH.NET 無法連線特定 SFTP 主機

 1 year ago
source link: https://blog.darkthread.net/blog/ssh-net-conn-forcibly-closed/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

【茶包射手日記】SSH.NET 無法連線特定 SFTP 主機-黑暗執行緒

某批次作業使用 SSH.NET 元件走 SFTP 上傳檔案,實測上傳多台 SFTP 伺服器中有一台失敗,其訊息為「An existing connection was forcibly closed by the remote host / 遠端主機已強制關閉一個現存的連線」:

Fig1_638116370944725137.png

該主機與成功上傳主機的差異在於它是台 Windows 2019 跑 OpenSSH Server,其餘皆為 Linux;但如果用 SFTP 客戶端程式連線是 OK 的:

Fig2_638116370946533247.png

依老司機的經驗,SSH/TLS 連線出現有些軟體可以某些不行的狀況,十之八九與程式支援的金鑰交換演算法、加密演算法及雜湊演算法有關。(例如:Chrome、Python 可以但 IE11、.NET 程式無法連線的 TLS 1.2 網站)

我裝了一台 Win 2019 VM 用 PowerShell 安裝 OpenSSH 伺服器實測並未發生連線被切斷的錯誤。比對了版本,發現依照官方文件步驟安裝的 OpenSSH.Server 版本為 7.7,但問題主機是從 Github 下載最新版安裝,為 9.1 版。(版本可使用 telnet 22 Port 觀察)
延伸閱讀:如何在 Windows 正確的安裝與設定 OpenSSH Server 服務 by 保哥

Fig3_638116370948303405.png

將 OpenSSH.Server 也升級到 9.1,果然就重現了連線強制關閉錯誤。

檢查發現程式用的 SSH.NET 元件版本是 2016.1,版本偏舊,與新版 OpenSSH Server 用的演算法可能無法匹敵,SSH.NET 2020 版有再多支援一些演算法。試著更新 SSH.NET 版本,問題解決,有驚無險。
註:網路上有 Ubuntu 20 OK、22 不行,但用 FileZilla 二者都沒問題的案例,推測也是類似問題。

and has 0 comments

Comments

Be the first to post a comment

Post a comment

Comment
Name Captcha 50 - 33 =

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK