我正在尝试对 AWS 托管实例执行 SSH 和 SCP。我的机器的公钥存储在该托管实例中。不需要 .pem 文件。我正在使用以下命令。
scp -r username@instance-id:/pathtoremotefile localpath
scp localfilepath username@instance-id:~
ssh username@instance-id
但是这些都不能在 Windows 中工作。错误显示,“CreateProcessW 失败错误:2 posix_spawn:没有这样的文件或目录丢失连接”。我要提到的是,我可以使用此命令启动到该实例的 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 相比,它是可靠的。
仅供参考,
感谢上述答案和评论,我解决了与@jass 的情况类似的问题。
对于我来说,当我尝试通过 ec2-instance 连接端点连接 ec2(在“单连接”情况下)时,我收到了相同的消息。
(参考:https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/connect-using-eice.html#eic-connect-using-ssh)
我在 Windows 中尝试使用 aws cli v2,并且已经配置了“aws configure”和 aws Access Key。
这是我找到的命令字符串。
ssh -i ~somin/.ssh/[xxxx.pem] ec2-user@[i-xxxxxxxxx] -o "ProxyCommand C:\Program Files\Amazon\AWSCLIV2\aws ec2-instance-connect open-tunnel --instance-id [i-xxxxxxxxx]"
P.s 但是,如果您尝试“多重连接”,则不会遇到任何错误。因为流程有两步,不存在路径问题。