Skip to content

feature-request: New-PSSession -HostName should be able to use the system's ssh-agent to get the required keys. #6207

Closed

Description

It'd be nice if we could use SSH PSRemote sessions with our configured session ssh-agent-compatible daemon to get the required security information/

For instance, I use gpg-agent to store my SSH private key securely on my Yubikey 4, as a result my key doesn't actually exist on my laptop.

From looking at the output of ps while New-PSSession is run, it appears you guys are shelling out to ssh anyway, and the ssh client supports the ssh-agent by default, so I assume something is being done to disable it for the invocation.

Activity

  1. iSazonov commented on Feb 21, 2018

    @iSazonov
    Collaborator

    /cc Paul Higinbotham (@PaulHigin) Could you please comment the feature request.

  2. PaulHigin commented on Feb 21, 2018

    @PaulHigin
    Contributor

    The idea is to let SSH handle the connection/transport for PS remoting. I don't know what the mechanism is for SSH to work with ssh-agent but PowerShell shouldn't get in the way. More details and repro steps can help determine if PowerShell is preventing this. We may have to update PowerShell code to support this, if possible.

  3. AmandaCameron commented on Feb 22, 2018

    @AmandaCameron
    Author

    A quick test just confirmed what I thought might be the issue -- the
    environment variables are being stripped by the time ssh is shelled out
    to.

    ssh uses the environment variable SSH_AUTH_SOCK to know where the unix
    socket for the ssh-agent is, so at least that needs to be preserved.

    I tested this with the following shell script placed in my $PATH before the
    normal location of ssh:

    #!/bin/sh
    
    env >/tmp/test-ssh.env
    exec /usr/bin/ssh "$@"
  4. added
    WG-Remoting
    on Feb 23, 2018
  5. PaulHigin commented on Feb 26, 2018

    @PaulHigin
    Contributor

    Yes, this looks like a bug in PowerShell when forking the ssh process. It is passing in an empty string array for the environment variables.

    https://github.com/PowerShell/PowerShell/blob/master/src/System.Management.Automation/engine/remoting/common/RunspaceConnectionInfo.cs#L2148

    I'll change this to a bug issue.

  6. added
    Issue-Bug
    on Feb 26, 2018
  7. AmandaCameron commented on May 27, 2018

    @AmandaCameron
    Author

    Any chance this can be bumped into 6.1.0? It's somewhat inconvient to be unable to use my securely-stored private key, instead having to use a password.

  8. PaulHigin commented on May 30, 2018

    @PaulHigin
    Contributor
  9. SteveL-MSFT commented on May 30, 2018

    @SteveL-MSFT
    Member

    Amanda Cameron (@AmandaCameron) 6.1.0-Consider means we're considering it for 6.1.0 already

    I know Paul Higinbotham (@PaulHigin) is currently busy with some other work, but this seems like something that shouldn't be too complicated to fix, so I'll leave it to Paul to address when he's able to

  10. PaulHigin commented on May 31, 2018

    @PaulHigin
    Contributor

    Ok, I'll look at a fix for 6.1.0 timeframe.

  11. 12 remaining items

  12. AmandaCameron commented on Jun 26, 2018

    @AmandaCameron
    Author

    Paul Higinbotham (@PaulHigin) I'm not sure what you mean by "parent process" I mentioned in an edit above that at the very least the powershell commandline knows of the auth socket, through $env:SSH_AUTH_SOCK -- the only env variable that my test script above is showing is PWD which is pointed to the directory containing the test ssh command script

  13. AmandaCameron commented on Jun 26, 2018

    @AmandaCameron
    Author

    I just checked the code, and while I'm not that familiar with C# -- this looks like where the startInfo is coming from? I'm not sure why that would have it's own copy of the parent's environment.

  14. PaulHigin commented on Jun 26, 2018

    @PaulHigin
    Contributor

    By parent process I mean the command line PowerShell process you are using to create a remote session. I assumed that the default StartInfo environment variables were obtained from the process in which it is currently running. My limited testing seemed to indicate that this was so, but maybe not since your $env:SSH_AUTH_SOCK setting doesn't seem to be propagating. I'll need to take a closer look.

  15. PaulHigin commented on Jul 10, 2018

    @PaulHigin
    Contributor

    I found some time to look at this some more and I can verify that StartInfo does indeed contain the parent process environment variables, including SSH_AUTH_SOCK, and that they are being passed into the ssh process used for the connection and transport. So there must be something else that prevents ssh-agent from working.

    I'll play around with ssh-agent to see if I can repro the problem.

  16. rkeithhill commented on Jul 11, 2018

    @rkeithhill
    Collaborator

    I'm confused about something here. The ssh-agent that comes with Git for Windows will create/use those env vars. But AFAICT, the ssh-agent that comes with OpenSSH (Windows 10 1803), it doesn't create or need those env vars.

  17. AmandaCameron commented on Jul 11, 2018

    @AmandaCameron
    Author

    Worth noting -- I'm running an Ubuntu-based laptop, not Windows where I'm encountering the issue.

    The steps I listed above to dump the environment variables was showing only PWD with the latest change.

  18. PaulHigin commented on Jul 11, 2018

    @PaulHigin
    Contributor

    I verified that the ssh process created by PowerShell remoting does not have the environment variables, by looking at the virtual file location /proc/[procid]/environ. It seems that our process creation code is not passing in the environment information correctly. I look deeper when I get some time.

  19. PaulHigin commented on Jul 12, 2018

    @PaulHigin
    Contributor

    My apologies. I was testing the old build without my fix and this is why I didn't see any environment variables. When I test a build with my fix I do now see the environment variables in the ssh process, including SSH_AUTH_SOCK. Next I'll see if I can get ssh-agent working.

  20. AmandaCameron commented on Jul 12, 2018

    @AmandaCameron
    Author
  21. PaulHigin commented on Jul 16, 2018

    @PaulHigin
    Contributor

    No problem. It looks like you did the same thing I did and tested on an older build. Glad to know it is working.

  22. added
    WG-Cmdlets
    and removed on Jul 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Issue-BugOS-LinuxResolution-FixedWG-CmdletsWG-Remoting

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions