sshpass-win32 icon indicating copy to clipboard operation
sshpass-win32 copied to clipboard

sshpass process hangs on Windows 11 when running SSH commands

Open pidgeon777 opened this issue 4 months ago β€’ 19 comments

Bug Description: When running the following command:

sshpass -p my_password ssh [email protected] ls

the sshpass process hangs and does not complete. I have to press Ctrl+C to stop the process manually.

Environment:

  • Operating System: Windows 11 Pro (Version 24H2, OS Build 26100.4946)

Steps to Reproduce:

  1. Install sshpass on Windows 11.
  2. Run the command above (replace credentials as needed).
  3. Observe that the process gets stuck and requires manual interruption.

Expected Behavior: The SSH command should execute and return the output of ls, then exit cleanly.

Actual Behavior: The process hangs indefinitely until Ctrl+C is pressed.

Additional Information:

  • This issue was observed with the Windows build described in the attached screenshot.
  • No specific error message is shown; the process just gets stuck.

pidgeon777 avatar Sep 02 '25 08:09 pidgeon777

I observed the same problem on WIndows 11. I needed this working, so I downloaded the source and got it building under VS2022. Took most of the day because I was not familiar with the code. Most of what I changed had to do with checking for errors, but I also made the -P string case InsEnsiTive, and changed how the command line is parsed (no trailing blank left at the end). It is working on Windows 11 Pro Version 10.0.26100.6584, tested with the Windows versions of SCP and SSH.

But it requires a different build environment (I could not get this source to build in VS2022, so I partied the code into a new Console project). Built as x64 to avoud Wow64 redirector issues (like CreateProcessA not finding ssh.exe or scp.exe, even with complete paths appended). Should this become a NEW repository, or...??

MainframeDaze avatar Sep 25 '25 23:09 MainframeDaze

This is great. Could you please fork the repository applying your changes in the meantime? So that it will be possible to obtain a working Windows 11 binary.

pidgeon777 avatar Sep 26 '25 06:09 pidgeon777

I will if I have time. Leaving town for a bit early tomorrow. May have to wait for my return (the project file needs some cleaning before I can post).

MainframeDaze avatar Sep 26 '25 20:09 MainframeDaze

I will if I have time. Leaving town for a bit early tomorrow. May have to wait for my return (the project file needs some cleaning before I can post).

I will wait in trepidation πŸ‘

pidgeon777 avatar Sep 26 '25 20:09 pidgeon777

Ok that took WAAAY too long. I forced the push to the forked branch I created. Let me know if it works for you, though I will not have time to help if it does not...

MainframeDaze avatar Sep 26 '25 22:09 MainframeDaze

I will wait in trepidation πŸ‘

Have you tried it yet?

MainframeDaze avatar Sep 28 '25 17:09 MainframeDaze

I will wait in trepidation πŸ‘

Have you tried it yet?

Not yet. I need my laptop, will do so in a couple of weeks πŸ‘.

pidgeon777 avatar Sep 28 '25 18:09 pidgeon777

I observed the same problem on WIndows 11. I needed this working, so I downloaded the source and got it building under VS2022. Took most of the day because I was not familiar with the code. Most of what I changed had to do with checking for errors, but I also made the -P string case InsEnsiTive, and changed how the command line is parsed (no trailing blank left at the end). It is working on Windows 11 Pro Version 10.0.26100.6584, tested with the Windows versions of SCP and SSH.

But it requires a different build environment (I could not get this source to build in VS2022, so I partied the code into a new Console project). Built as x64 to avoud Wow64 redirector issues (like CreateProcessA not finding ssh.exe or scp.exe, even with complete paths appended). Should this become a NEW repository, or...??

I've switched to CreateProcessW - see if that resolves the redirector issue.

xhcoding avatar Sep 29 '25 15:09 xhcoding

Sorry but CreateProcessW won’t make a difference. The redirector engages on all 32-but processes running on x64, unless you make specific calls to turn the wow reddirector on and off.

MainframeDaze avatar Sep 29 '25 20:09 MainframeDaze

Ok that took WAAAY too long. I forced the push to the forked branch I created. Let me know if it works for you, though I will not have time to help if it does not...

Hello MainframeDaze, I just compiled your fork and try to execute the program, once in powershell 7.5 and once in cmd. I'm running Windows 11 Pro 24H2 build 26100.6584

Powershell output:

SSHPass.exe -h
ResourceUnavailable: Program 'SSHPass.exe' failed to run: An error occurred trying to start process 'C:\Users\user\git-output\SSHPass.exe' with working directory 'C:\Users\user\git-output'. The operation was canceled by the user.At line:1 char:1
+ .\SSHPass.exe -h
+ ~~~~~~~~~~~~~~~~.

cmd output:

SSHPass.exe -h
This version of C:\Users\user\git-output\SSHPass.exe is not compatible with the version of Windows you're running. Check your computer's system information and then contact the software publisher.

No setttings are changed, just open the project and build.

wrbst avatar Oct 07 '25 10:10 wrbst

Re-written, sorry. Initial post was from my phone.

Are you running 64-bit Windows? The project as configured creates an x64 build, in no small part because that is the version of Windows I need it for; trying to run the x64 build on 32-bit Windows would give you the error message you see.

The original project I forked this from is for 32-bit Windows. Have you tried that version? If you build this version/fork for i86 (32-bit) and you have a 32-bit system, it should work, but I do not have a 32-bit system on which to test it. The 32-bit version on x64 fails to launch SSH and SCP due to the WOW64 Redirector.

MainframeDaze avatar Oct 07 '25 16:10 MainframeDaze

Re-written, sorry. Initial post was from my phone.

Are you running 64-bit Windows? The project as configured creates an x64 build, in no small part because that is the version of Windows I need it for; trying to run the x64 build on 32-bit Windows would give you the error message you see.

The original project I forked this from is for 32-bit Windows. Have you tried that version? If you build this version/fork for i86 (32-bit) and you have a 32-bit system, it should work, but I do not have a 32-bit system on which to test it. The 32-bit version on x64 fails to launch SSH and SCP due to the WOW64 Redirector.

Yes, Windows 11 is exclusively a 64-bit operating system and does not have a 32-bit version. Official statement from Microsoft. The sshpass.exe from xhcoding repo hangs and it's not working as expected. I will check (debug) what is going on and later on update you.

wrbst avatar Oct 07 '25 21:10 wrbst

Yes, Windows 11 is exclusively a 64-bit operating system and does not have a 32-bit version. Official statement from Microsoft. The sshpass.exe from xhcoding repo hangs and it's not working as expected. I will check (debug) what is going on and later on update you.

Ok, try a Build / Rebuild Solution in VS2022 and let me know what errors, if any, you get. Ensure that it is targeting x64 and not x86. You should expect some type case and conversion WARNINGS for SSHPass.cpp, but no build errors.

"SSHPass -h" or just "SSHPass" should show the help message.

MainframeDaze avatar Oct 07 '25 23:10 MainframeDaze

The sshpass.exe from xhcoding repo hangs and it's not working as expected

This is happening because SSH and SCP live in a directory that isn’t found when the WOW 64 Redirector kicks in; that version is compiled for x86. That’s what led me to create my fork in the first place. Do let me know what you find when you check on the build parameters for this fork. Note that I had to make some changes to include directories to get the version of the SDK that I have installed. That might be tripping you up in the build.

[updated 8 hours later] I dropped in the compiled binary from my system as v2.0.0-alpha and released it.

MainframeDaze avatar Oct 09 '25 21:10 MainframeDaze

I will wait in trepidation πŸ‘

Have you tried it yet?

Not yet. I need my laptop, will do so in a couple of weeks πŸ‘.

Any word?

MainframeDaze avatar Oct 12 '25 21:10 MainframeDaze

@wrbst

Powershell output:

SSHPass.exe -h ResourceUnavailable: Program 'SSHPass.exe' failed to run: An error occurred trying to start process 'C:\Users\user\git-output\SSHPass.exe' with working directory 'C:\Users\user\git-output'. The operation was canceled by the user.At line:1 char:1

  • .\SSHPass.exe -h
  • 
    

cmd output:

SSHPass.exe -h This version of C:\Users\user\git-output\SSHPass.exe is not compatible with the version of Windows you're running. Check your computer's system information and then contact the software publisher.

No setttings are changed, just open the project and build.

Did the compiled binary I uploaded last month work for you?

MainframeDaze avatar Nov 20 '25 00:11 MainframeDaze

I will wait in trepidation πŸ‘

Have you tried it yet?

Not yet. I need my laptop, will do so in a couple of weeks πŸ‘.

Any word?

I tried your v2.0.0 alpha release, with:

C:\Users\<USERNAME>\Downloads>sshpass -p my_password ssh [email protected] ls
WFMO result 1

Tried to connect to the Google server. Is that an expected/working output?

pidgeon777 avatar Nov 30 '25 18:11 pidgeon777

[EDITED with more information]

I tried your v2.0.0 alpha release, with:

C:\Users\<USERNAME>\Downloads>sshpass -p my_password ssh [email protected] ls
WFMO result 1

Tried to connect to the Google server. Is that an expected/working output?

The WFMO message is the WaitForMultipleObjects() return value, which means it received a PROCESS EXIT code from the SSH process.

The WFMO message is new logic, and it only shows up when there is not console INPUT taken. It's a debug aid I put in place when I was getting SSHPASS to work in 64-bit mode.

I tried a command similar to yours: SSHPASS -p{password} ssh admin@{appliance_DNS_NAME} "ls -l >/tmp/foo.txt"

Then I SSH'd back in without an argument to execute and found that /tmp/foo.txt did indeed exist. So the command ran. Again, the WFMO result output is a debug aid I put in that I should probably remove now. Try this with output redirection and see what happens. I bet that the default directory had nothing in it, so you did not see any output. That is why I used "ls -l" because at least that captured the "total 0" result on my appliance. Or try "ls /" to dump the root directory instead.

MainframeDaze avatar Nov 30 '25 20:11 MainframeDaze

I just pushed v2.0.1 with the WFMO message removed.

MainframeDaze avatar Dec 01 '25 00:12 MainframeDaze

I have great news, we went to this test website:

https://test.rebex.net/

And tried your v2.0.0 version. It worked fine:

C:\Users\<USERNAME>\Downloads>sshpass -p "password" ssh -o StrictHostKeyChecking=no -l demo test.rebex.net "ls -la"

drwx------ 2 demo users          0 Mar 31  2023 .
drwx------ 2 demo users          0 Mar 31  2023 ..
drwx------ 2 demo users          0 Mar 31  2023 pub
-rw------- 1 demo users        379 Sep 19  2023 readme.txt
WFMO result 1

@MainframeDaze, first of all, thanks for your great contribution.

Secondly, I really need you could replace in your post here:

https://github.com/xhcoding/sshpass-win32/issues/10#issuecomment-3593285534

the real username of my colleague's account. We forgot to remove it when posting the comment here. Something such as <USERNAME> as a replacement would be good. Thanks in advance πŸ‘.

pidgeon777 avatar Dec 02 '25 15:12 pidgeon777

@xhcoding, maybe this fork could be merged?

https://github.com/MainframeDaze/sshpass-win32

Also, @MainframeDaze, I see that your fork maybe would need a rebase?

Image

pidgeon777 avatar Dec 02 '25 15:12 pidgeon777

@pidgeon777:

Secondly, I really need you could replace in your post here:

#10 (comment)

the real username of my colleague's account. We forgot to remove it when posting the comment here. Something such as as a replacement would be good. Thanks in advance πŸ‘.

Done

MainframeDaze avatar Dec 02 '25 17:12 MainframeDaze

@pidgeon777

@xhcoding, maybe this fork could be merged?

https://github.com/MainframeDaze/sshpass-win32

Also, @MainframeDaze, I see that your fork maybe would need a rebase?

It most certainly would. It would require either reverting to ANSI (from Unicode in the current @xhcoding tree) then merging other changes. Or for me to convert to Unicode, which can be done but is not needed to make things work (as you saw from your tests). There would also be the minor change of renaming the sshpass.cpp to main.c (or vice-versa). Finally working out any changes from my building for C++ vs. the originals in C.

Not something I would have time for until next year, at the earliest.

MainframeDaze avatar Dec 02 '25 21:12 MainframeDaze

Still, thanks for your contribution. Do you think that your v2.0.1 version could be usable for common sshpass operations in its current state? And which are the current big differences between your release and @xhcoding current binaries?

pidgeon777 avatar Dec 03 '25 15:12 pidgeon777

I plan on using my V2.0.2 release in my environment. Off the top of my head, the biggest difference is in the versions are:

  1. My fork is 64 bit; the original fork is 32 bit. A 32 bit app is subject to the WOW64 redirector, which is why it could not find SSH on the path. I’ve also tested it with SCP.
  2. My fork allows substring matches for the password prompt string.
  3. The original fork uses Unicode (added after I forked). My fork still uses ANSI.

I think that covers the functional differences, but I’m not in front of a computer where I can run a diff right now.

MainframeDaze avatar Dec 03 '25 18:12 MainframeDaze