3

I used this guide to install OpenSSH from WinSCP's website.

I used the msi installer that is listed on the github page https://github.com/PowerShell/Win32-OpenSSH/releases.

The server seems to be running but after trying to login I get:

---------------------------
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   
---------------------------

On the server machine there seems to be an sshd running and listening on port 22 (copied from TCPview) :

Process PID Protocol State Local Address Local Port Remote Address Remote Port Create Time Module name
sshd.exe 5844 TCP Listen 0.0.0.0 22 0.0.0.0 0 8/19/2022 6:49:33 PM sshd
sshd.exe 5844 TCPv6 Listen :: 22 :: 0 8/19/2022 6:49:33 PM sshd

I have not changed the default sshd_config

Update:

Using putty and the same user name and password works and I can browse directories.

Here's putty vs WinScp:

putty_vs_winscp

(Where red and orange are username and machine name respectively)

FW rules are defined:

Firewall_rules

4
  • How exactly are you trying to connect? Is port 22 open on the server's firewall?
    – squillman
    Aug 22, 2022 at 22:21
  • Using WinSCP and the machine name of the "server" machine. I believe it does create FW rules as part of the setup, I can see allow rules for port 22 in the inbound rule list: imgur.com/a/iiEoFBB
    – Scis
    Aug 22, 2022 at 22:27
  • Using putty and the same user name and password works and I can browse directories. @squillman
    – Scis
    Aug 22, 2022 at 22:29
  • 1
    Can you post screenshots of the WinSCP and putty connections (recommend you paste them into the question instead of imgur)
    – squillman
    Aug 22, 2022 at 22:34

2 Answers 2

6

The issue was that sftp-server.exe was not in PATH. Adding the installation path C:\Program Files\OpenSSH and restarting the service with Restart-Service sshd solved the issue.

I diagnosed by setting

SyslogFacility LOCAL0
LogLevel DEBUG3

in C:\ProgramData\ssh\sshd_config

And noticing that it complained about not finding it

subsystem: cannot stat sftp-server.exe: No such file or directory
0

To resolve the problem, open of SSH server config on Windows (usually located at C:\ProgramData\ssh\sshd_config).


First, replace sftp-server.exe with line <absolute-path-to>/sftp-server.exe.

It seems that setting PATH is useless on my side.


Second, comment or remove lines beginning with ForceCommand if exists.

It helps resolve most of the unknown errors from SFTP clients. However, there is a side effect that SSH clients will use CMD as the default shell.

To use PowerShell as the default shell edit SSH client config (usually located at~/.ssh/config):

Host <host>
  ...
  RemoteCommand powershell

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .