无需代理转发的 SSH 跳转主机

无需代理转发的 SSH 跳转主机

虽然是一个简单的问题,但我搜索了好几天都没有结果。

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.

答案1

问题是它试图使用我的密钥 (M) 在 S 中验证身份,而它应该使用 J 的密钥。我无法指定要与 IdentityFile 一起使用的密钥,因为它在 J 上,而不是在我的计算机上。

嗯,这就是你的问题。在此设置中,与跳转主机和最终目的地的连接都直接从你的客户端发起。你的客户端必须拥有两个系统的正确密钥。

代理命令中的命令ssh jump -W %h:%p会启动到跳转主机的 ssh 会话,但不会创建 shell,它只会直接创建到目标主机的隧道。然后,您的客户端会通过 ssh 连接到隧道。在这种设置中,跳转主机上不会启动 shell,因此您无法访问存储在中间主机上的任何密钥。乱用转发不会产生任何效果。不会使用转发来启动连接。

答案2

您无需登录防火墙,它是一种限制数据包的网络设备。在这种情况下,它基本上是不可见的。必须对其进行配置,以允许您的数据包到达堡垒主机 (jumphost) 服务器,该服务器的端口为 22,可能为高范围端口。

您直接登录服务器,因此需要对其进行配置以允许这样做。从同一网络上的另一台机器进行测试。从此堡垒主机,您可以登录到它在您的私有子网中保护的机器。

根据进一步信息进行更新 您不需要目标服务器中的堡垒/跳转主机密钥,您需要的是您的密钥。试图访问服务器的不是堡垒,而是用户,即您。

退一步来说。确保你可以使用你的密钥从同一子网中的另一台服务器使用 ssh 访问目标服务器。然后从堡垒主机尝试。

相关内容