在 Windows 10 上无法使用 ProxyCommand 通过跳转主机进行 ssh

在 Windows 10 上无法使用 ProxyCommand 通过跳转主机进行 ssh

我的配置文件如下(我试图直接ssh进入 foo):

Host foo
    HostName <ip>
    User <username>
    ProxyCommand C:\Windows\System32\OpenSSH\ssh.exe -q -W %h:%p jump

Host jump
    HostName <ip>
    User <username>
    ProxyCommand C:\Windows\System32\OpenSSH\ssh.exe -q -W %h:%p bar

Host bar
    HostName <ip>
    User <username>
    Port <num>

此外,我已将我的id_rsa.pub密钥连接到authorized_keysbar、jump 和 foo 服务器。当我运行 时ssh -J foo jump bar,我收到错误CreateProcessW failed error:2 posix_spawn: No such file or directory。当我尝试时,ssh foo -v我收到以下信息:

OpenSSH_for_Windows_7.7p1, LibreSSL 2.6.5
debug1: Reading configuration data C:\\Users\\CCL/.ssh/config
debug1: C:\\Users\\CCL/.ssh/config line 7: Applying options for foo
debug1: Executing proxy command: exec C:\\Windows\\System32\\OpenSSH\\ssh.exe -q -W <jump_ip> jump
debug1: identity file C:\\Users\\CCL/.ssh/id_rsa type 0
debug1: key_load_public: No such file or directory
debug1: identity file C:\\Users\\CCL/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file C:\\Users\\CCL/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file C:\\Users\\CCL/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file C:\\Users\\CCL/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file C:\\Users\\CCL/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file C:\\Users\\CCL/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file C:\\Users\\CCL/.ssh/id_ed25519-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file C:\\Users\\CCL/.ssh/id_xmss type -1
debug1: key_load_public: No such file or directory
debug1: identity file C:\\Users\\CCL/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_for_Windows_7.7

同样,当我尝试时ssh jump -v,我得到

OpenSSH_for_Windows_7.7p1, LibreSSL 2.6.5
debug1: Reading configuration data C:\\Users\\CCL/.ssh/config
debug1: C:\\Users\\CCL/.ssh/config line 12: Applying options for jump
debug1: Executing proxy command: exec C:\\Windows\\System32\\OpenSSH\\ssh.exe -q -W <bar_ip:port_num> bar
debug1: identity file C:\\Users\\CCL/.ssh/id_rsa type 0
debug1: key_load_public: No such file or directory
debug1: identity file C:\\Users\\CCL/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file C:\\Users\\CCL/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file C:\\Users\\CCL/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file C:\\Users\\CCL/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file C:\\Users\\CCL/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file C:\\Users\\CCL/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file C:\\Users\\CCL/.ssh/id_ed25519-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file C:\\Users\\CCL/.ssh/id_xmss type -1
debug1: key_load_public: No such file or directory
debug1: identity file C:\\Users\\CCL/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_for_Windows_7.7

ssh 进程似乎卡住了,无法进行身份验证,也无法进行密钥交换。我该如何修复这个问题?

答案1

听起来你正在尝试使用bar作为跳转主机连接到jump,并使用jump作为跳转主机连接到foo。换句话说,尝试bar像这样连接到:

local --> foo --> jump --> bar

你的 ssh 配置应该如下所示:

Host foo
    HostName <ip>
    User <username>
    ProxyJump jump

Host jump
    HostName <ip>
    User <username>
    ProxyJump bar

Host bar
    HostName <ip>
    User <username>
    Port <num>

然后要连接,只需运行ssh bar

ProxyJump是比 更简单的获取所需内容的方法ProxyCommand,假设您使用的是 OpenSSH 7.3 或更新版本。此外,您无需在命令-J上使用ssh。 为当前调用-J设置ProxyJump,如果它已存在于您的配置文件中,则不需要。

相关内容