
我使用本指南安裝 OpenSSHWinSCP 的網站。
我使用了msi
github 頁面上列出的安裝程序https://github.com/PowerShell/Win32-OpenSSH/releases。
伺服器似乎正在運行,但嘗試登入後我得到:
---------------------------
Error
---------------------------
Connection has been unexpectedly closed. Server sent command exit status 1.
---------------------------
Cannot initialize SFTP protocol. Is the host running an SFTP server?
---------------------------
OK Reconnect Help
---------------------------
在伺服器電腦上似乎有一個 sshd 正在運行並偵聽連接埠 22(從 TCPview 複製):
過程 | PID | 協定 | 狀態 | 本地地址 | 本地埠 | 遠端位址 | 遠端埠 | 創造時間 | 模組名稱 |
---|---|---|---|---|---|---|---|---|---|
sshd.exe | 5844 | 傳輸控制協定 | 聽 | 0.0.0.0 | 22 | 0.0.0.0 | 0 | 2022 年 8 月 19 日 6:49:33 下午 | sshd |
sshd.exe | 5844 | TCPv6 | 聽 | :: | 22 | :: | 0 | 2022 年 8 月 19 日 6:49:33 下午 | sshd |
我沒有更改預設值sshd_config
更新:
使用 putty 和相同的使用者名稱和密碼可以工作,我可以瀏覽目錄。
這是 putty 與 WinScp 的比較:
(其中紅色和橘色分別是使用者名稱和機器名稱)
FW規則定義:
答案1
問題是它sftp-server.exe
不在PATH
.新增安裝路徑C:\Program Files\OpenSSH
並重新啟動服務即可Restart-Service sshd
解決問題。
我透過設定診斷
SyslogFacility LOCAL0
LogLevel DEBUG3
在C:\ProgramData\ssh\sshd_config
並注意到它抱怨沒有找到它
subsystem: cannot stat sftp-server.exe: No such file or directory
答案2
若要解決該問題,請在 Windows 上開啟 SSH 伺服器設定(通常位於C:\ProgramData\ssh\sshd_config
)。
首先,替換sftp-server.exe
為 line <absolute-path-to>/sftp-server.exe
。
看來這個設定PATH
對我來說沒什麼用。
其次,註解或刪除以ForceCommand
if contains 開頭的行。
它有助於解決來自 SFTP 用戶端的大多數未知錯誤。但是,有一個副作用,即 SSH 用戶端將使用 CMD 作為預設 shell。
若要使用 PowerShell 作為預設 shell,請編輯 SSH 用戶端設定(通常位於~/.ssh/config
):
Host <host>
...
RemoteCommand powershell