SSH 和 SCP 失败,并显示“CreateProcessW failed error:2 posix_spawn: No such file or directory”

Jas*_*ass 6 windows ssh cmd scp amazon-web-services

我正在尝试对 AWS 托管实例执行 SSH 和 SCP。我机器的公钥存储在该托管实例中。不需要 .pem 文件。我正在使用以下命令。

   scp -r  username@instance-id:/pathtoremotefile localpath
   scp localfilepath  username@instance-id:~
   ssh  username@instance-id
Run Code Online (Sandbox Code Playgroud)

但是这些都没有在 Windows 中工作。错误说,“CreateProcessW failed error:2 posix_spawn: No such file or directory lost connection”。我会提到我可以使用此命令启动与该实例的 ssm 会话

   aws ssm start-session --target instance-id.
Run Code Online (Sandbox Code Playgroud)

托管实例有 linux 操作系统,我的电脑有 Windows。另外,在 .ssh 目录的配置文件中,我添加了以下几行。

 host i-* mi-*
ProxyCommand sh -c "aws ssm start-session --target %h --document-name AWS-StartSSHSession --parameters 'portNumber=%p'"
Run Code Online (Sandbox Code Playgroud)

奇怪的是,我可以使用相同的命令在同一台机器上的“Linux 的 windows 子系统”中同时执行 ssh 和 SCP。但是在 Windows 命令提示符下无法做到这一点。我究竟做错了什么?

jeb*_*jeb 10

这似乎是 Windows openSSH 包的问题。在 ProxyCommands 中,它请求完整路径限定符,但最好在那里使用正斜杠!

ProxyCommand C:/somepath/sh.exe -c "aws ssm ...
Run Code Online (Sandbox Code Playgroud)

我不再使用 windows openSSH,而是使用 git-bash 中的 ssh 命令来避免所有 windows 问题。
关键代理工作完美,proxyCommand/proxyJumps 工作,与 windows 相比,它是可靠的。

  • 谢谢@jeb,我明白我做错了什么。我应该使用的代理命令是不同的。我使用的是 linux 命令,但对于 Windows,它应该是这样的: # SSH over Session Manager host i-* mi-* ProxyCommand C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe "aws ssm start-会话 --目标 %h --文档名称 AWS-StartSSHSession --参数 portNumber=%p"。谢谢我从你的回答中找到了方法。 (2认同)