使用具有多个证书的 SSH 公钥

jan*_*jan 5 security ssh certificate client-certificate

我正在使用 SSH 公钥连接到多个服务器。服务器使用 SSH CA 来管理授权用户。基本概念如下所述: https: //www.digitalocean.com/community/tutorials/how-to-create-an-ssh-ca-to-validate-hosts-and-clients-with-ubuntu

因此,除了我常用的id_rsa文件之外id_rsa.pub,我还有一个id_rsa-cert.pub包含证书的文件。所有这些都运行得很好,我可以立即登录到配置为信任用于签署我的密钥的 CA 密钥的新计算机。

然而,我现在得到了由不同 CA 为不同机器组签名的密钥。现在的问题是,我如何告诉 SSH 现在这个密钥有两个证书。从文档来看,似乎无法指定第二个证书文件:

ssh(1) will try to load certificate information from the filename
obtained by appending -cert.pub to the path of a specified IdentityFile.
Run Code Online (Sandbox Code Playgroud)

简单地将新证书附加到此文件(就像您对 所做的那样authorized_keys)也不起作用。在这种情况下,SSH 仍将仅识别第一个证书并忽略文件的其余部分。

有谁知道如何告诉 SSH 我有这个密钥的第二个证书?

pim*_*pim 2

由于您使用相同的私钥并且ssh将使用密钥名称来猜测证书名称,因此复制您的私钥和公钥:

cp ~.ssh/id_rsa id_rsa_group2
cp ~.ssh/id_rsa.pub id_rsa_group2.pub # probably not necessary
Run Code Online (Sandbox Code Playgroud)

然后使证书的名称匹配,应该是id_rsa_group2-cert.pub

测试一下:ssh -i .ssh/id_rsa_group2 ip_of_your_server

然后通过编辑使键选择自动~/.ssh/config

# For your first certificate:
Host a
    User root
    IdentityFile ~/.ssh/id_rsa

# For your new certificate
Host b
    User root
    IdentityFile ~/.ssh/id_rsa_group2
Run Code Online (Sandbox Code Playgroud)