question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Users with a profile which outputs anything cannot create PSSessions over SSH

See original GitHub issue

Prerequisites

Steps to reproduce

  1. If OpenSSHD is not already present, install it (e.g. on Windows run Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0)
  2. Enable Remote sessions over ssh by editing the sshd config file as described in https://learn.microsoft.com/en-us/powershell/scripting/learn/remoting/ssh-remoting-in-powershell-core?view=powershell-7.2 (on Windows copy C:\Windows\System32\OpenSSH\sshd_config_default to C:\ProgramData\ssh\sshd_config to give yourself a file to start from)
  3. Backup your profile.ps1 if you have one, and create a simple profile.ps1 e.g. 'hello'
  4. run new-PSSession -HostName localhost
  5. Observe the error New-PSSession: [localhost] There is an error processing data from the background process. Error reported: Hello.
  6. Think “A-ha I need to use -NoProfile so SSH works like WinRM”, modify the config file, restart the sshd Service, try again, curse when the same error occurs

Expected behavior

PS>  new-PSSession  -HostName localhost
xxxx@localhost's password:

 Id Name            Transport ComputerName    ComputerType    State         ConfigurationName     Availability
 -- ----            --------- ------------    ------------    -----         -----------------     ------------
  5 Runspace4       SSH       localhost       RemoteMachine   Opened        DefaultShell             Available

Actual behavior

PS>  new-PSSession  -HostName localhost
xxxx@localhost's password:
New-PSSession: [localhost] There is an error processing data from the background process. Error reported: Hello.

Error details

New-PSSession: [localhost] There is an error processing data from the background process. Error reported: Hello.

Environment data

PS>  $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.3.0-preview.7
PSEdition                      Core
GitCommitId                    7.3.0-preview.7
OS                             Microsoft Windows 10.0.22000
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

image

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:11 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
jhoneillcommented, Sep 18, 2022

@237dmitry It’s not the prompt. image

Just connecting using SSH with pwsh set as the default shell for sshd is fine. There are two things with PSSessions

  1. A PSSession over WSMan does not process the profile. The command to start pwsh in an ssh subsystem Subsystem powershell c:/progra~1/powershell/7/pwsh.exe -sshs ... does.
  2. Any output form subsystem at start up seems to cause an error

I think (2) is expected with openssh -if you don’t specify -NoLogo in the subsystem you get an error citing the the PowerShell version message (The way I have installed 7.3 preview means I can’t test on that - the help I linked to above says the -NoLogo isn’t needed in 7.3, so this symptom may have been silently fixed)

But (1)… PSSessions should do the same things regardless of the connection mechanism. But the -sshs switch doesn’t do that automatically and causes -NoProfile to be ignored unless someone tells me that has also changed for 7.3

It seems that if the user is a member of admins, ssh connections are always as admin. Since I’m testing on my local machine I’m using New-PSSession -EnableNetworkAccess -ComputerName localhost for winrm, and I think that inherits the token from the current session because if I connect from PowerShell run as admin, my PSSession returns true for [System.Security.Principal.WindowsIdentity]::GetCurrent().Groups.Value -contains 'S-1-5-32-544' and if I run from PowerShell un-elevated, it returns false. AIUI this is specific to -EnableNetworkAccess not to winrm so the should in “PSSessions should do the same things regardless of the connection mechanism.” is not a must

1reaction
dkaszewscommented, Sep 17, 2022

@jhoneill Sorry, got confused because the title says SSH

Read more comments on GitHub >

github_iconTop Results From Across the Web

PowerShell Remoting Over SSH
PSRemoting over SSH doesn't support Profiles and doesn't have access to $PROFILE . Once in a session, you can load a profile by...
Read more >
Enter-PSSession - PowerShell
The Enter-PSSession cmdlet starts an interactive session with a single remote computer. During the session, the commands that you type run on the...
Read more >
Enter-PSSession: Running Remote Commands in ...
Enter-PSSession cmdlet allows you to establish a persistent interactive PowerShell session with a remote computer. All commands you enter in ...
Read more >
windows 10 - Powershell Profile is not available over ssh
I have installed openssh on my windows 10 desktop through the apps and features menu. I can ssh to the machine and see...
Read more >
PowerShell SSH Client and Remoting Explained
Use PowerShell as an SSH client or run PowerShell code another server with PowerShell remoting over SSH. How to get started.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found