没有代理转发的 SSH 跳转主机

SSH Jump Host WITHOUT Agent Forwarding

虽然是个简单的问题,我找了好几天都没有成功。

M = My machine 
J = Jump Host
S = Server

Jump Host has my public key on authorized_keys.
Server has J's public key on authorized_keys.

Allowed connections (due to key authentication):
M -> J
J -> S

我怎么可能从我的机器上通过 ssh 进入 S?

我当前的配置是:

host jump
  user root
  HostName x.x.x.x

host server
  user root
  HostName x.x.x.x
  port 22
  ForwardAgent no
  ProxyCommand ssh jump -W %h:%p

尝试使用 M 的密钥登录时无法正常工作。

这是 ssh 日志

debug1: Host 'x.x.x.x' is known and matches the ECDSA host key.
debug1: Found key in /Users/xxxxx/.ssh/known_hosts:1542
...
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /Users/xxxxx/.ssh/id_rsa
debug1: Authentications that can continue: publickey
debug1: Trying private key: /Users/xxxxx/.ssh/id_dsa
debug1: Trying private key: /Users/xxxxx/.ssh/id_ecdsa
debug1: Trying private key: /Users/xxxxx/.ssh/id_ed25519
debug1: No more authentication methods to try.
Permission denied (publickey).
Killed by signal 1.

是的。当然,它会尝试使用 M 的密钥登录。你并不是真的从 J 连接到 S。

第一个 ssh 连接是从 M 到 J。这个只是设置了一些转发。第二个 ssh 连接使用第一个 ssh 建立的转发直接从 M 到 S。 - 没有机会使用 J 上的钥匙。

您可以使用 ssh -A jump ssh-add 将 J 的密钥添加到您的代理中。 那么您的设置应该可以正常工作。

另一个想法可能类似于 ssh -t jump ssh server。通过这种方式,您可以登录到 J,然后从那里登录到 S,这与您预期的差不多。