gpt4 book ai didi

ssh - 为什么 ssh-agent 不转发我的 SSH 证书?

转载 作者:行者123 更新时间:2023-12-04 12:54:12 31 4
gpt4 key购买 nike

This thread is a response to the titled question : Why ssh-agent doesn't forward my SSH certificate ? Actually I couldn't find any information during my search. I had to read the C code of ssh-add to resolve my issue..

问题

我获得了有效的 SSH 证书:

$ ssh-keygen -L -f ~/.ssh/id_rsa-cert.pub 
/home/user/.ssh/id_rsa-cert.pub:
Type: ssh-rsa-cert-v01@openssh.com user certificate
Public key: RSA-CERT SHA256:YgFzKPkUdZHLLi8bEKUs5/hLumNoMNG+oDJ+KD6mS3s
Signing CA: RSA SHA256:w+Cjpu/QQUunuojs9Af82ENdBUreCDXo+APao9X4dHw
Key ID: "user_key"
Serial: 0
Valid: from 2017-12-06T10:53:00 to 2017-12-07T10:54:57
Principals:
user
admin
Critical Options: (none)
Extensions:
permit-X11-forwarding
permit-agent-forwarding
permit-port-forwarding
permit-pty
permit-user-rc

这是我的 ssh-agent key 列表:

$ ssh-add -l
4096 SHA256:YgFzKPkUdAGBPi8bEKUs5/hLumNoAds+oDJ+KD6mS3s user_key (RSA)

当我在远程服务器上 SSH 时,它可以工作。我没有 ~/.ssh/authorized_keys 并且我的 key 可能被很好地转发,因为我得到了相同的先前结果。

现在我想从第一个服务器通过 SSH 连接到另一台服务器(使用 ForwardAgent 是):

$ ssh srv1
srv1:~$ ssh srv2 -vvv
...
debug3: authmethod_is_enabled publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: user_key
debug3: send_pubkey_test
debug2: we sent a publickey packet, wait for reply
...
Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).
srv1:~$

我做错了什么?

最佳答案

事实上,ssh-agent 并没有很好地接受我的 SSH 证书。我们可以看到它是一个 RSA 而不是 RSA-CERT。如何在 ssh-agent 中导入证书?

您必须有 2 个键(位置和命名很重要):

  • 原始 RSA 对:
    • 私钥:~/.ssh/example_key
    • 公钥:~/.ssh/example_key .pub
  • RSA 证书:
    • 私钥/证书:~/.ssh/example_key -cert
    • 公共(public)证书:~/.ssh/example_key -cert.pub

然后导入原来的一对:

$ ssh-add ~/.ssh/example_key
Enter passphrase for /home/user/.ssh/example_key:
Identity added: /home/user/.ssh/example_key (/home/user/.ssh/example_key)
Certificate added: /home/user/.ssh/example_key-cert.pub (user)

自动添加证书。

然后,SSH 代理转发它没有问题。同时,如果不移除 SSH 证书,是无法从代理中删除原始 RSA Key 对的。

$ ssh-add -l
4096 SHA256:YgFzKPkUdAGBPi8bEKUs5/hLumNoAds+oDJ+KD6mS3s user_key (RSA)
4096 SHA256:YgFzKPkUdAGBPi8bEKUs5/hLumNoAds+oDJ+KD6mS3s user_key (RSA-CERT)
$ ssh srv1
srv1:~$ ssh srv2
srv2:~$

回顾:为什么错了,为什么?

  • 我的 key 命名错误。我的 RSA 对类似于 ~/.ssh/id_rsa_github 而我的 SSH 证书是 ~/.ssh/id_rsa-cert
  • 代理错误地导入了我的证书并将其视为身份而不是证书。
  • 在第一次 SSH 连接期间,代理将证书作为身份提供,但它可以与远程 openssh 服务器协商(我真的不知道为什么)。在第二次 SSH 连接期间,它无法...

也要注意这一点:

  • 在证书扩展中添加 permit-agent-forwarding
  • ForwardAgent yes 放入您的 SSH 客户端配置中

最后,我使用 CASSH 签署证书。

关于ssh - 为什么 ssh-agent 不转发我的 SSH 证书?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47679715/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com