Issue
I am trying to run the SSH command from the Power shell on Windows 11. I have the OpenSSH installed and this used to work until some update when it stopped. I get the following response:
C:\Users\ivan> ssh
ssh : The term 'ssh' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ ssh
+ ~~~
+ CategoryInfo : ObjectNotFound: (ssh:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
However when I print the path variable OpenSSH directory is clearly in the path:
PS C:\Users\ivan> $env:path
%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;%SYSTEMROOT%\System32\OpenSSH\;C:\Program Files\TortoiseSVN\bin;C:\Program Files\Docker\Docker\resources\bin;C:\ProgramData\DockerDesktop\version-bin;C:\Program Files\usbipd-win\;C:\Program Files\dotnet\;
When I print the SYSTEMROOT:
PS C:\Users\ivan> $env:systemroot
C:\WINDOWS
And when I move manually to the directory which is %systemroot%\System32\OpenSSH\ and try to run the SSH it runs:
PS C:\Users\ivan> cd C:\windows\system32\OpenSSH\
PS C:\windows\system32\OpenSSH> ./ssh
usage: ssh [-46AaCfGgKkMNnqsTtVvXxYy] [-B bind_interface]
[-b bind_address] [-c cipher_spec] [-D [bind_address:]port]
[-E log_file] [-e escape_char] [-F configfile] [-I pkcs11]
[-i identity_file] [-J [user@]host[:port]] [-L address]
[-l login_name] [-m mac_spec] [-O ctl_cmd] [-o option] [-p port]
[-Q query_option] [-R address] [-S ctl_path] [-W host:port]
[-w local_tun[:remote_tun]] destination [command]
My guess is that systemroot variable substitution goes sideways, but I am not sure how.
Solution
after some research i've found this issue https://github.com/PowerShell/PowerShell/issues/11774 and like mentioned there the solution was to uninstall the 32bit PowerShell and install the 64bit version of Powershell.
If you have the 32bit version
Get-Item -Force C:\Windows\System32\OpenSSH\ssh.exe
# Fails with:
Get-Item: Cannot find path 'C:\Windows\System32\OpenSSH\ssh.exe' because it does not exist.
Answered By - rayphi Answer Checked By - Marilyn (WPSolving Volunteer)