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:
Subsystem is NOT honored when using ssh.exe. Subsystem IS honored when using the *-PSSession cmdlets.
- 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:
- SSHExe_No_DefaultShell_In_Registry: https://gist.github.com/pldmgg/3fa040a73ce6f83385dbc05acb96cf1a
- 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:
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!
Goal:
Enter an interactive pwsh.exe session on a (Windows) Remote Host using SSH Public Cert Authentication using BOTH ssh.exe AND pwsh.exe
*-PSSessioncmdletsRequirements:
Subsystemsshd_config option must be usedForceCommandsshd_config option must NOT be usedDefaultShellas pwsh.exe underHKLM:\SOFTWARE\OpenSSHif necessaryEnvironment
Relevant info about ssh client and sshd server machines:
sshd -dddis run manually on the sshd server for each test in order to collect logs)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)ssh-rsa-cert-v01@openssh.com AAAA... C:\Users\zeroadmin\.ssh\zeroadmin_090618_114109is loaded in the ssh-agent on the clientWhat 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:
For completeness sake,
C:\Users\zeroadmin\.ssh\zeroadmin_090618-cert.pubis in this format:What Does Not Work:
*-PSSessionpwsh.exe cmdlets to work under any circumstances (using SSH Cert Auth).Subsystemsetting. What I SHOULD see in sshd logs is the following......What I always end up seeing is the following...
Full sshd logs can be found under the relevant SCENARIO sections below.
Side Note: Using the pwshe.exe
*-PSSessioncmdlets DOES honorSubsystem(i.e., I see the desiredStarting 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)
DefaultShellEntry in Registry - NOForceCommand pwsh.exe -NoProfileimplemented in sshd_config - YESSubsystem powershell C:/symlinks/pwsh.exe -sshs -NoLogo -NoProfileimplemented in sshd_config -YES(NOTE:
C:/symlinks/pwsh.exeis a symlink toC:/Program Files/Powershell/6-preview/pwsh.exe)Result
*-PSSessioncmdlets on the client side fail for some unknown reason (FAILURE)Subsystemis NOT honored when using ssh.exe.SubsystemIS honored when using the*-PSSessioncmdlets.ForceCommand pwsh.exe -NoProfiletoForceCommand pwsh.exe -sshs -NoLogo -NoProfilecauses ssh.exe to hang on the client side, but things look okay on the sshd sideLOGS:
SCENARIO 2:
Config Info (these are the ONLY things that are changed from the above sshd_config between testing scenarios)
DefaultShellEntry in Registry ofC:/Program Files/Powershell/6-preview/pwsh.exe- YESForceCommandimplemented in sshd_config - NOSubsystem powershell C:/symlinks/pwsh.exe -sshs -NoLogo -NoProfileimplemented in sshd_config -YES(NOTE:
C:/symlinks/pwsh.exeis a symlink toC:/Program Files/Powershell/6-preview/pwsh.exe)Result
*-PSSessioncmdlets on the client side fail for some unknown reason (FAILURE)Subsystemis NOT honored when using ssh.exe.SubsystemIS honored when using the*-PSSessioncmdlets.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:
Attempting to connect using SSH Cert Auth via the
*-PSSessioncmdlets (i.e. the-HostName,-KeyFilePath, and optionally the-SSHTransportparameters) has never been successful under any circumstances. Specifically I tried the following under all testing scenarios that I attempted...Thanks in advance for any help!