【问题标题】:Why ssh-agent doesn't forward my SSH certificate?为什么 ssh-agent 不转发我的 SSH 证书?
【发布时间】:2017-12-07 06:28:07
【问题描述】:

这个帖子是对标题问题的回应:为什么 ssh-agent 不转发我的 SSH 证书? 实际上,我在搜索过程中找不到任何信息。我不得不read the C code of ssh-add 解决我的问题..

问题

我获得了有效的 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 密钥列表:

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

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

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

$ 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 certificate ssh-agent


【解决方案1】:

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

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

  • 原始 RSA 对:
    • 私钥:~/.ssh/example_key
    • 公钥:~/.ssh/example_key .pub
  • RSA 证书:
    • 私钥/证书:~/.ssh/example_key -cert
    • 公共证书:~/.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:~$ 

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

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

也要注意这一点:

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

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

【讨论】:

  • 谢谢!这行得通。我的一个建议是澄清证书的命名约定。仅当您在证书文件末尾添加 -cert.pub 时它才有效。你把它放在那里,但没有明确提及。
猜你喜欢
  • 2017-07-13
  • 1970-01-01
  • 2021-10-27
  • 2022-12-16
  • 2018-10-14
  • 2017-11-04
  • 1970-01-01
  • 1970-01-01
  • 2023-01-13
相关资源
最近更新 更多