Issue
in my target scenario I need to connect remotely from linux to windows and execute powershell commands. For this, I have installed the native open ssh server on windows and pwoershell core 6 on both machines.
Remoting works just fine if I use password authentication on sshd. It does not work when requiring key-based authentication.
PS /> Enter-PSSession -HostName computername -UserName 'domain\username' -KeyFilePath ./sshkeys/win/win10 -Verbose
Enter passphrase for key '/sshkeys/win/win10':
Enter-PSSession : The background process reported an error with the following message: The SSH client session has ended with error message: Connection to computername closed by remote host..
At line:1 char:1
+ Enter-PSSession -HostName computername -UserName 'domain\username' -KeyFilePath ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (:) [Enter-PSSession], PSRemotingTransportException
Does someone know what might be causing the error here?
Solution
For anyone interested, I resolved this issue by further researching.
The command/setup is perfectly fine, but there was an outstanding issue with the open ssh server's version included with the bundle I installed with "Add-WindowsCapability" cmdlet.
This bundle installed version 7.6p1-beta on my Win10 machine. But as a matter of fact this issue has been fixed as of 7.6.1p1-beta, see: https://github.com/PowerShell/Win32-OpenSSH/issues/1098
Manually downloading and running the latest version of the SSH Server fixed it for me.
Answered By - baouss