You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Unable to use scp with -oUserKnownHostsFile that has spaces #1211
What is failing
When launching ssh and scp from another process, I'm passing in arguments to specify a known hosts file and key. Note I'm not launching these as a shell process.
For ssh,
Command = C:\PathToSSH\ssh.exe
Args = [
-FNUL -ic:\space test\ssh\id_rsa,
-oStrictHostKeyChecking=yes,
-oUserKnownHostsFile="c:\space test\ssh\known_hosts",
myuser@myserver
]
Actual output
The ssh commmand works as expected.
The scp command fails with this error:
ssh: Could not resolve hostname test/ssh/known_hosts: No such host is known.
Since scp appears to invoke ssh, it appears that it is not properly passing in the path with spaces.
The "arguments as array" example was for launching from Go.
I've reproduced the problem in C# as well, using triple-quotes to pass the quotes through the process object (since it takes arguments as a single string). This is the equivalent string being passed into C#'s ProcessStartInfo.Arguments:
... -FNUL -oStrictHostKeyChecking=yes -oUserKnownHostsFile="""c:\space test\ssh\known_hosts""" ...
After looking into this a bit, I believe the spawn_child_internal function needs to escape arguments containing string when it generates the ssh command line.
Currently it builds the command line by taking every arg in the list, adding a space to the command line string and then adding the arg surrounded by quotes. This results in a command like:
... "UserKnownHostsFile="c:/space test/ssh/known_hosts"" ...
The inner quotes likely needs to be replaced with something like " or """
Activity
cbookg commentedon Jul 9, 2018
The "arguments as array" example was for launching from Go.
I've reproduced the problem in C# as well, using triple-quotes to pass the quotes through the process object (since it takes arguments as a single string). This is the equivalent string being passed into C#'s ProcessStartInfo.Arguments:
... -FNUL -oStrictHostKeyChecking=yes -oUserKnownHostsFile="""c:\space test\ssh\known_hosts""" ...
Again, this works for launching ssh, but not scp.
cbookg commentedon Jul 12, 2018
After looking into this a bit, I believe the spawn_child_internal function needs to escape arguments containing string when it generates the ssh command line.
Currently it builds the command line by taking every arg in the list, adding a space to the command line string and then adding the arg surrounded by quotes. This results in a command like:
... "UserKnownHostsFile="c:/space test/ssh/known_hosts"" ...
The inner quotes likely needs to be replaced with something like " or """
cbookg commentedon Jul 12, 2018
In my last line the backslash was filtered out of my comment. Should have been (backslash)" or """
1. Add fix for PowerShell/Win32-OpenSSH#1211
Fix of 1211 and 1082 (#349)
cbookg commentedon Nov 19, 2018
It looks like this may be fixed, but there hasn't been a release since July to pick this up. Is there an ETA for the next release?
AvtechScientific commentedon Oct 19, 2021
Danny Maertens (@maertendMSFT) - was this issue indeed resolved? Judging by #1784 it looks, like it is still around...
Fix of 1211 and 1082 (PowerShell#349)