Skip to content

SSH Between 2 Windows Machines Using pwsh.exe and OpenSSH-Win64 with SSH Cert Auth #7728

@pldmgg

Description

@pldmgg

Goal:

Enter an interactive pwsh.exe session on a (Windows) Remote Host using SSH Public Cert Authentication using BOTH ssh.exe AND pwsh.exe *-PSSession cmdlets

Requirements:

  • SSH Client must be on a Windows OS
  • SSHD Server must be on a Windows OS
  • SSH Cert Authentication must be used
  • The Subsystem sshd_config option must be used
  • The ForceCommand sshd_config option must NOT be used
  • Optionally specify DefaultShell as pwsh.exe under HKLM:\SOFTWARE\OpenSSH if necessary

Environment

Relevant info about ssh client and sshd server machines:

  • zerotesting5.zero.lab (192.168.2.13) is the localhost (client) and zerowin16sshb.zero.lab (192.168.2.53) is the Remote Host (server).
  • Both are running Windows 2016 Standard
  • Both have pwsh 6.1.0-rc1 (and ONLY pwsh 6.1.0-rc1) installed
  • Both are running OpenSSH-Win64 7.7.2.0
  • ssh-agent Service is running on both machines (sshd -ddd is run manually on the sshd server for each test in order to collect logs)
  • Each machine's Signed Host Cert (ssh-rsa-cert-v01@openssh.com AAAA... C:\ProgramData\ssh\ssh_host_rsa_key) is loaded in the ssh-agent for both client and server (not sure if this is necessary)
  • zero\zeroadmin's SSH Cert ssh-rsa-cert-v01@openssh.com AAAA... C:\Users\zeroadmin\.ssh\zeroadmin_090618_114109 is loaded in the ssh-agent on the client
  • Baseline sshd_config is as follows: https://gist.github.com/pldmgg/2850f834889fc430c08e3fd4e735c3e3

What Works Beyond Any Doubt:

Testing so far proves that SSH Certificate Authentication is configured properly since I can consistently get to an interactive cmd.exe session on the Remote Host via any of the following commands:

ssh zeroadmin@zero@zerowin16sshb

ssh -o "IdentitiesOnly=true" -i "C:\Users\zeroadmin\.ssh\zeroadmin_090618" -i "C:\Users\zeroadmin\.ssh\zeroadmin_090618-cert.pub" zeroadmin@zero@zerowin16sshb

ssh -o "IdentitiesOnly=true" -i "C:\Users\zeroadmin\.ssh\zeroadmin_090618" zeroadmin@zero@zerowin16sshb

For completeness sake, C:\Users\zeroadmin\.ssh\zeroadmin_090618-cert.pub is in this format:

ssh-rsa-cert-v01@openssh.com AAAA...<truncated>...Bg==

What Does Not Work:

  • I have not been able to get any of the *-PSSession pwsh.exe cmdlets to work under any circumstances (using SSH Cert Auth).
  • The above ssh.exe commands NEVER honor the sshd_config Subsystem setting. What I SHOULD see in sshd logs is the following...
Starting session: subsystem 'powershell' for zero\\zeroadmin from 192.168.2.13 port 51060 id 0

...What I always end up seeing is the following...

Starting session: shell on windows-pty for zero\\zeroadmin from 192.168.2.13 port 50944 id 0

Full sshd logs can be found under the relevant SCENARIO sections below.

Side Note: Using the pwshe.exe *-PSSession cmdlets DOES honor Subsystem (i.e., I see the desired Starting session: subsystem ... in sshd logs), however, they never actually create a PSSession.

The Closest I Got to Satisfying Requirements:

SCENARIO 1:

Config Info (these are the ONLY things that are changed from the above sshd_config between testing scenarios)

  • DefaultShell Entry in Registry - NO
  • ForceCommand pwsh.exe -NoProfile implemented in sshd_config - YES
  • Subsystem powershell C:/symlinks/pwsh.exe -sshs -NoLogo -NoProfile implemented in sshd_config -YES
    (NOTE: C:/symlinks/pwsh.exe is a symlink to C:/Program Files/Powershell/6-preview/pwsh.exe)

Result

  • The aforementioned ssh commands place me in pwsh.exe on the Remote Host (SUCCESS)
  • *-PSSession cmdlets on the client side fail for some unknown reason (FAILURE)
  • Additional Notes:
  1. Subsystem is NOT honored when using ssh.exe. Subsystem IS honored when using the *-PSSession cmdlets.
  2. Changing ForceCommand pwsh.exe -NoProfile to ForceCommand pwsh.exe -sshs -NoLogo -NoProfile causes ssh.exe to hang on the client side, but things look okay on the sshd side

LOGS:

  1. SSHExe_No_DefaultShell_In_Registry: https://gist.github.com/pldmgg/3fa040a73ce6f83385dbc05acb96cf1a
  2. New-PSSession_No_DefaultShell_In_Registry: https://gist.github.com/pldmgg/6cf1a2e1ca02ae540062222fc50bbb63

SCENARIO 2:

Config Info (these are the ONLY things that are changed from the above sshd_config between testing scenarios)

  • DefaultShell Entry in Registry of C:/Program Files/Powershell/6-preview/pwsh.exe - YES
  • ForceCommand implemented in sshd_config - NO
  • Subsystem powershell C:/symlinks/pwsh.exe -sshs -NoLogo -NoProfile implemented in sshd_config -YES
    (NOTE: C:/symlinks/pwsh.exe is a symlink to C:/Program Files/Powershell/6-preview/pwsh.exe)

Result

  • The aforementioned ssh commands place me in pwsh.exe on the Remote Host (SUCCESS)
  • *-PSSession cmdlets on the client side fail for some unknown reason (FAILURE)
  • Additional Notes:
  1. Subsystem is NOT honored when using ssh.exe. Subsystem IS honored when using the *-PSSession cmdlets.

LOGS:
I can post this as public gists, but long story short, the same problems mentioned in the "What Does Not Work" section above apply.

ALL OTHER SCENARIOS:

Trying config settings other than those outlined in the above 2 Scenarios always resulted in one of the following outcomes:

  • Placed me in cmd.exe on the Remote Host
  • Prevented me from connecting altogether
  • Hung indefinitely on either Client or SSHD side

Attempting to connect using SSH Cert Auth via the *-PSSession cmdlets (i.e. the -HostName, -KeyFilePath, and optionally the -SSHTransport parameters) has never been successful under any circumstances. Specifically I tried the following under all testing scenarios that I attempted...

New-PSSession -HostName zerowin16sshb -UserName zero\zeroadmin -KeyFilePath "C:\Users\zeroadmin\.ssh\zeroadmin_090618-cert.pub"

New-PSSession -HostName zerowin16sshb -UserName zero\zeroadmin -KeyFilePath "C:\Users\zeroadmin\.ssh\zeroadmin_090618"

New-PSSession -HostName zerowin16sshb -UserName zeroadmin -KeyFilePath "C:\Users\zeroadmin\.ssh\zeroadmin_090618-cert.pub"

New-PSSession -HostName zerowin16sshb -UserName zeroadmin -KeyFilePath "C:\Users\zeroadmin\.ssh\zeroadmin_090618"

New-PSSession -HostName zerowin16sshb -UserName zero\zeroadmin -KeyFilePath "C:\Users\zeroadmin\.ssh\zeroadmin_090618-cert.pub" -SSHTransport

New-PSSession -HostName zerowin16sshb -UserName zero\zeroadmin -KeyFilePath "C:\Users\zeroadmin\.ssh\zeroadmin_090618" -SSHTransport

New-PSSession -HostName zerowin16sshb -UserName zeroadmin -KeyFilePath "C:\Users\zeroadmin\.ssh\zeroadmin_090618-cert.pub" -SSHTransport

New-PSSession -HostName zerowin16sshb -UserName zeroadmin -KeyFilePath "C:\Users\zeroadmin\.ssh\zeroadmin_090618" -SSHTransport

Thanks in advance for any help!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifResolution-AnsweredThe question is answered.WG-RemotingPSRP issues with any transport layer

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions