我想在 Windows 中通过命令行建立提供代理的 SSH 连接。当我将 ssh 命令与 ssh -o "ProxyCommand proxytunnel.exe ..."一起使用时,它给了我一个错误,例如
CreateProcessW failed error:2 posix_spawn: No such file or directory
另外,在 putty.exe 命令行中,我尝试了 -proxycmd="proxytunnel.exe .."但这也给出了错误。
有什么推荐的方法来建立通过 CMD 提供代理的 SSH 连接吗?
提前致谢!
最佳答案
普通系统上的语法是(但 Windows 上不是):
ssh user@myHost -p 4711 -oProxyCommand="ssh jumphost -W %h:%p"
或使用 proxytunnel
ssh user@myHost -p 4711 -oProxyCommand="proxytunnnel.exe args"
@MartinPrikryl 的评论让我想起了另一个问题。
留言CreateProcessW failed error:2 posix_spawn: No such file or directory
这是 Windows 10 系统的典型情况,因为 ssh 在 ProxyCommand 选项中甚至无法找到 ssh.exe 本身。
您始终需要在 Windows 上指定完整路径,甚至是 .exe
是必需的。
ssh user@myHost -p 4711 -oProxyCommand="C:\Windows\System32\OpenSSH\ssh.exe jumphost -W %h:%p"
在 .ssh/config 文件中使用完整路径是可能的(最好使用正斜杠),但会导致更多问题,当您使用 git-bash 时,ssh-agent 会定期中断。
或者最好完全避免使用 Windows 中的 OpenSSH,而始终使用 git-bash 中的 ssh,因为这样效果更好,并且与 ssh-agent(来自 git-bash 的 ssh-agent)配合使用也可靠。< br/> 然后甚至可以通过跳转主机轻松使用 vscode。
关于ssh - 在 Windows 中通过 cmd 为 ssh 命令或 putty 提供代理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64422347/