GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fixes SSH Remoting KeyFilePath Parameter by PaulHigin · Pull Request #4529 · PowerShell/PowerShell

Conversation

@PaulHigin

@PaulHigin Paul Higinbotham (PaulHigin) commented Aug 8, 2017

Copy link
Copy Markdown
Contributor

This change addresses issue #4475.

When creating the SSH child process for remoting the KeyFilePath parameter path was enclosed in double quotes to handle potential space characters in the file path. The problem was that the new SSH child process creation code was leaving the quote characters in the key filepath causing SSH to fail to find the key file. In addition KeyFilePath paths with space characters were not being handled correctly.

With this change the KeyFilePath parameter now works as expected:

PS > New-PSSession -HostName Machine1 -UserName User1 -KeyFilePath c:\users\User1\Keys\User1Key

PS > New-PSSession -HostName Machine2 -UserName User2 -KeyFilePath "c:\users\User2\My Keys\User2Key"

This worked correctly on Windows and only failed on Linux systems using the new SSH process creation code.


I also noticed and fixed a problem where trying to back out of a SSH remoting password prompt resulted in a hang (until the 1 minute protocol timeout occurred).

PS > New-PSSession -HostName Machine1 -UserName User1
User1@Machine1's password:  
Ctrl+C

The problem was that the client side connection did not end. Fix is to add CloseAsync override to close the connection.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Paul Higinbotham (PaulHigin) added 2 commits August 8, 2017 13:06
@PaulHigin
Fixes KeyFilePath parameter for Linux systems
e1b51ee
@PaulHigin
Merge branch 'Fix-KeyFilePath-Parameter' of github.com:PaulHigin/Powe…
fdd2da0
…rShell into Fix-KeyFilePath-Parameter
@msftclas Microsoft Contribution License Agreements (msftclas) added the cla-not-required label Aug 8, 2017
@PaulHigin Paul Higinbotham (PaulHigin) added WG-Remoting PSRP issues with any transport layer Issue-Bug Issue has been identified as a bug in the product OS-Linux OS-macOS labels Aug 8, 2017
@PaulHigin Paul Higinbotham (PaulHigin) added this to the 6.0.0-HighPriority milestone Aug 8, 2017
@PaulHigin Paul Higinbotham (PaulHigin) assigned Aditya Patwardhan (adityapatwardhan) Aug 8, 2017
@PaulHigin
Paul Higinbotham (PaulHigin) requested a review from Mike Richmond (mirichmo) August 8, 2017 21:27
mirichmo
Mike Richmond (mirichmo) reviewed Aug 9, 2017
View reviewed changes
Comment thread src/System.Management.Automation/engine/remoting/common/RunspaceConnectionInfo.cs
case '"':
// Special case for arguments within quotes
// Just return argument value within the quotes
while ((++i < argsLength) && argsToParse[i] != '"') { };

@mirichmo Mike Richmond (mirichmo) Aug 9, 2017

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there enforcement for the string ending in a '"'? Does that happen in a different layer?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@PaulHigin Paul Higinbotham (PaulHigin) Aug 10, 2017

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No enforcement here. This expects the argument string to be correctly formatted. If it is not then the argument list is wrong and any errors are generated when the process is created.

This is currently scoped internally so we currently have complete control in how it is used. However, I did intend this to be robust against malformed strings (empty, single quote, unmatched quotes, single space, only spaces, etc.). If you see something I missed please let me know.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@mirichmo Mike Richmond (mirichmo) Aug 10, 2017

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My initial concern regarded unmatched double quotes. Thinking about it some more, two other things came to mind:

  1. Strings that use single quotes
  2. Argument lists that include other commands. Do we do validation on it? I'm wondering about something like this: arg1 arg2; rm -rf *

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@PaulHigin Paul Higinbotham (PaulHigin) Aug 10, 2017

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Single quotes are not supported and not needed. It is something we could add if we need it in the future. Argument validation is not intended to be performed here. This just parses space delimited strings with a special case for double quoted arguments.

I just tried to make sure it doesn't blow up with malformed strings and cause an access violation or null reference exception.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
mirichmo
Mike Richmond (mirichmo) approved these changes Aug 10, 2017
View reviewed changes
@PaulHigin

Paul Higinbotham (PaulHigin) commented Aug 14, 2017

Copy link
Copy Markdown
Contributor Author

Aditya Patwardhan (@adityapatwardhan)
Can this be merged? Thanks.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@adityapatwardhan

Aditya Patwardhan (adityapatwardhan) commented Aug 14, 2017

Copy link
Copy Markdown
Member

Paul Higinbotham (@PaulHigin) Can we add tests for this?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@PaulHigin

Paul Higinbotham (PaulHigin) commented Aug 14, 2017

Copy link
Copy Markdown
Contributor Author

#3904

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@adityapatwardhan
Aditya Patwardhan (adityapatwardhan) merged commit 6b8d86f into PowerShell:master Aug 15, 2017
@PaulHigin

Paul Higinbotham (PaulHigin) commented Aug 15, 2017

Copy link
Copy Markdown
Contributor Author

Thanks!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@PaulHigin Paul Higinbotham (PaulHigin) mentioned this pull request Aug 15, 2017
SSH KeyFilePath parameter not working #4475
Closed
@PaulHigin
Paul Higinbotham (PaulHigin) deleted the Fix-KeyFilePath-Parameter branch August 28, 2017 23:11
@Hema-dell

Hema-dell commented Jan 13, 2020 •
edited by unfurl-links Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

HI ,
I have installed PoSH6 and 7 on Windows 10 box, and PoSh6 on linux box, trying to do remote throush PsSession using -keyfilepath, followed instructions for ssh as provided in https://docs.microsoft.com/en-us/windows-server/administration/openssh/openssh_install_firstuse, after following the instructions and providing this command : New-PSSession -HostName [email protected]:22 -KeyFilePath C:\Users\dell.ssh\authorized_keys i get prompt for password , i have copied authorized_keys into ./ssh folder of linux box too!!! why is it prompting for password?

Installation of OpenSSH For Windows
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@PaulHigin

Paul Higinbotham (PaulHigin) commented Jan 13, 2020 •
edited by unfurl-links Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

Hema-dell It sounds like your sshd_config configuration file still allows password authentication and should be disabled. FYI, I have a module with 'Enable-SSHRemomting' cmdlet that I have been working on. It is not been published by you can experiment with it if you like:
https://gist.github.com/PaulHigin/b12b552b12dc4e8c940efe4f402e5362

We decided not to touch general SSH settings, and assume that the user has it set up as needed. The 'Enable-SSHRemoting' cmdlet merely updates the sshd_config file with subsytem entry that becomes a PowerShell SSH remoting end point, so that the machine can receive connections.

Gist
PSRemotingTools module
PSRemotingTools module. GitHub Gist: instantly share code, notes, and snippets.
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Hema-dell

Hema-dell commented Jan 14, 2020

Copy link
Copy Markdown

Hi Paul!!,
I tried the above steps as shared in the link by you ,however i am still unable to do pssession using -keyfilepath parameter!!!!, Need your help on this!!!!.

Thanks,
Hema-dell

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Thatgfsj (Thatgfsj) pushed a commit to Thatgfsj-contribs/PowerShell that referenced this pull request Aug 6, 2026
@PaulHigin @adityapatwardhan
Fixes KeyFilePath parameter for Linux systems (PowerShell#4529)
9d72135
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

1 more reviewer
@mirichmo Mike Richmond (mirichmo) mirichmo approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@adityapatwardhan Aditya Patwardhan (adityapatwardhan)

Labels

Issue-Bug Issue has been identified as a bug in the product OS-Linux OS-macOS WG-Remoting PSRP issues with any transport layer

Projects

None yet

Milestone

6.0.0-GA

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

5 participants

@PaulHigin @adityapatwardhan @Hema-dell @mirichmo @msftclas
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.