Skip to content

Powershell Subsystem Fails when using a banner in OpenSSH #5142

Closed

Description

Using a Banner option within sshd_config causes the connection to fail

Banner /etc/ssh/banner

If we comment out the Banner line, and restart sshd, client connections work just fine.

Steps to reproduce

PS /Users/drewstinnett> Enter-PSSession -Host host.example.com -SSHTransport -UserName drews
Enter-PSSession : The background process reported an error with the following message: The SSH client session has ended with error message:
####
# Example Banner
####
At line:1 char:1
+ Enter-PSSession -Host host.example.com -SSHTransport -UserNam ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (:) [Enter-PSSession], PSRemotingTransportException
    + FullyQualifiedErrorId : System.Management.Automation.Remoting.PSRemotingDataStructureException,Microsoft.PowerShell.Commands.EnterPSSessionCommand

PS /Users/drewstinnett>

Expected behavior

PS /Users/drewstinnett> Enter-PSSession -Host host.example.com -SSHTransport -UserName drews
####
# Example Banner
####
[host.example.com]: PS /home/drews>

Actual behavior

PS /Users/drewstinnett> Enter-PSSession -Host host.example.com -SSHTransport -UserName drews
Enter-PSSession : The background process reported an error with the following message: The SSH client session has ended with error message:
####
# Example Banner
####
At line:1 char:1
+ Enter-PSSession -Host host.example.com -SSHTransport -UserNam ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (:) [Enter-PSSession], PSRemotingTransportException
    + FullyQualifiedErrorId : System.Management.Automation.Remoting.PSRemotingDataStructureException,Microsoft.PowerShell.Commands.EnterPSSessionCommand

PS /Users/drewstinnett>

Environment data

PowerShell v6.0.0-beta.8
Copyright (C) Microsoft Corporation. All rights reserved.

PS /root> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      6.0.0-beta.8
PSEdition                      Core
GitCommitId                    v6.0.0-beta.8
OS                             Linux 3.10.0-693.2.2.el7.x86_64 #1 SMP Sat Sep 9 03:55:24 EDT 2017
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0


PS /root>

Activity

  1. added
    WG-Remoting
    on Oct 17, 2017
  2. added this to the milestone on Oct 17, 2017
  3. PaulHigin commented on Oct 20, 2017

    @PaulHigin
    Contributor

    PowerShell currently uses stderror messages to determine if ssh client fails during remoting initial connection, such as an authorization failure or some configuration caused failure, and then reports the failure message to the user. But this is turning out to be unreliable since ssh passes warnings and (now) banner text stderror too.

    The banner text comes through stderror and PowerShell cannot distinguish it from a real ssh error, so it closes the session. PowerShell currently looks for "WARNING:" prepended to a stderror message and ignores those. But I don't see a way to ignore a random string appearing in stderror.

    This is only for the initial connection and the protocol handles connection errors after that. I think we will need to add some kind of connection integrity check before starting the protocol to ensure the initial connection succeeded. It will involve ensuring the ssh client process is alive since it will terminate on error.

    In the mean time the workaround is to not turn on the banner message for sshd configuration.

  4. added
    Issue-Enhancement
    on Apr 14, 2018
  5. JacobStruiksma commented on May 18, 2020

    @JacobStruiksma

    Is this issue going to be investigated?If a banner is used (for example in corporate environments with a legal statement before connecting to a linux machine) , you need a windows machine for powershell remoting to other linux machines.

  6. JacobStruiksma commented on Jan 16, 2021

    @JacobStruiksma

    It still does not work as expected.

    The clients as the destination is installed with Powershell 7.1.1
    The destination linux machine is properly configured with an banner for sshd.

    On the client windows machine, i don't see the banner. On the client linux machine i got an error.

    On a windows machine I got the following:

    PS C:\Users\username> Enter-PSSession -HostName rpi2.localdomain -UserName pi
    [pi@rpi2.localdomain]: PS /home/pi>

    On a linux machine I got the following:

    PS /home/pi> Enter-PSSession -HostName rpi2.localdomain -UserName pi
    Enter-PSSession: The background process reported an error with the following message: The SSH client session has ended with error message: ###
    # banner
    ###.
    PS /home/pi/.ssh> ssh pi@rpi2.localdomain
    ###
    # banner
    ###
    Linux rpi2 5.4.83-v7+ #1379 SMP Mon Dec 14 13:08:57 GMT 2020 armv7l
    
    The programs included with the Debian GNU/Linux system are free software;
    the exact distribution terms for each program are described in the
    individual files in /usr/share/doc/*/copyright.
    
    Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
    permitted by applicable law.
    Last login: Sat Jan 16 13:19:40 2021 from 192.168.1.14
    pi@rpi2:~ $
  7. JacobStruiksma commented on Aug 18, 2021

    @JacobStruiksma

    Still not working for Powershell 7.1.4 or 7.2.0-preview.8. Enable-ExperimentalFeature PSNotApplyErrorActionToStderr does not seem to help. Using -ErrorAction continue on New-PSSession does also not change the result

  8. thukk commented on Oct 6, 2021

    @thukk

    Any update on progress with this bug? This issue also happens when attempting to created a connection from Linux to Linux. I can bypass the SSH prompt by setting no banner in sssh_config, but if FIPs Mode is enabled, the connection errors out as SSH says "The background process reported an error with the following message: The SSH client session has ended with error message: FIPS mode initialized."

    Even if it writes to stderr, that is fine - but at least make it respect the ErrorAction setting (it currently Stops, regardless of the set Error Action). That would be bare minimum.

  9. thukk commented on Nov 10, 2022

    @thukk

    Can confirm - this works with PowerShell 7.3. Suggest closing the issue.

  10. JacobStruiksma commented on Nov 24, 2022

    @JacobStruiksma

    Works for me too. issue has been resolved.

  11. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  12. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  13. added
    Resolution-No Activity
    on Nov 16, 2023
  14. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  15. microsoft-github-policy-service commented on Nov 23, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-EnhancementResolution-No ActivityWG-Remoting

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions