I'm working on an Azure DevOps pipeline Classic UI that deploys a software package to multiple Windows devices registered in Deployment Groups.
The flow:
Copying SSH Keys:
- We copy a private key file (
id_rsa) and other supporting files from a deployment package into the target machine's.sshfolder:C:\path1\path2\path3 files\path4\path5\.ssh\id_rsa - Permissions are set (FullControl for the intended user) and the file is confirmed to exist.
- We copy a private key file (
Attempting SSH Connection:
- Using PowerShell, we run an SSH command to connect to a required endpoint for the software (endpoint name masked for security).
- The SSH command should prompt for a fingerprint, which we expect to accept (i.e., first time connection should add to known_hosts).
The problem:
- The SSH command consistently fails:
Warning: Identity file C:\path1\path2\path3 not accessible: No such file or directory. ssh: Could not resolve hostname files\\path4\\path5\\.ssh\\id_rsa: No such host is known. - The
id_rsafile does exist confirmed by script and manual inspection. - The SSH command seems to split the argument at the space in "path3 files", treating the rest as a hostname.
What we've tried:
- Quoting the Key Path:
- Tried
"C:\path1\path2\path3 files\path4\path5\.ssh\id_rsa"with explicit quotes in the SSH command.
- Tried
- PowerShell Array Arguments:
- Passed arguments to
Start-Processas an array, e.g.:$argList = @( "-i", $sshKeyPath, "-T", "-o", "StrictHostKeyChecking=accept-new", "$remoteUser@$hostEndpoint", "exit" ) Start-Process -FilePath $sshExe -ArgumentList $argList
- Passed arguments to
- Running via cmd.exe:
- As a workaround, used
cmd.exe /c "ssh ..."so the Windows shell parses the arguments, e.g.:$sshCmd = "ssh -i `"$sshKeyPath`" -T ... $remoteUser@$hostEndpoint exit" Start-Process -FilePath "cmd.exe" -ArgumentList "/c $sshCmd"
- As a workaround, used
- Permissions:
- Ensured the target user has FullControl on the key file and parent directory.
Expected Result:
- SSH should prompt for fingerprint acceptance (first connection) and complete the handshake.
- The connection should succeed using the provided key.
Actual Result:
- SSH always fails, reporting the key file path is not accessible or that it cannot resolve part of the path as a hostname.
Questions:
- Why is SSH not correctly parsing the path to the key file, even when quoted?
- Is there a recommended PowerShell practice for reliably passing a path with spaces to OpenSSH on Windows from a pipeline context?
- Are there additional tricks for handling key acceptance/fingerprints in a non-interactive deployment scenario?
- Are there alternative ways to run SSH from PowerShell that avoid argument splitting issues?
Extra context:
- The pipeline is running as SYSTEM.
- All sensitive names, endpoints, and product names are intentionally masked.
Any help or guidance is appreciated!
') or use the8.3name, see also: Spaces cause split in path with PowerShell.