SSH和SCP失败,并显示“CreateProcessWfailederror:2posix_spawn:Nosuchfileordirectory”

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

   scp -r  username@instance-id:/pathtoremotefile localpath
   scp localfilepath  username@instance-id:~
   ssh  username@instance-id

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

   aws ssm start-session --target instance-id.

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

 host i-* mi-*
ProxyCommand sh -c "aws ssm start-session --target %h --document-name AWS-StartSSHSession --parameters 'portNumber=%p'"

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

回答

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

ProxyCommand C:/somepath/sh.exe -c "aws ssm ...

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

  • Thanks @jeb , I understood what I was doing wrong. The proxy command that I should use was different. I was using linux command , but for windows, it should be like this: # SSH over Session Manager
    host i-* mi-*
    ProxyCommand C:WindowsSystem32WindowsPowerShellv1.0powershell.exe "aws ssm start-session --target %h --document-name AWS-StartSSHSession --parameters portNumber=%p". Thanks I got the way from your answer.

以上是SSH和SCP失败,并显示“CreateProcessWfailederror:2posix_spawn:Nosuchfileordirectory”的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>