如何在一个连接中使用多个 ssh 密钥?

如何在一个连接中使用多个 ssh 密钥?

我的组织有一台服务器,它要求一个 ssh 连接同时使用两个身份文件。就像这样:ssh -i /first/key -i /second/key user@host 我想知道它是如何实现的?如何配置我自己的 SSH 服务器,使其同时要求一个客户端使用两个身份文件?

答案1

这是由AuthenticationMethods这由OpenSSH 配置部分来自文档,最相关的部分是:

If the publickey method is listed more than once, sshd(8) verifies that keys that
have been used successfully are not reused for subsequent authentications.  For
example, "publickey,publickey" requires successful authentication using two
different public keys.

这正是您要求做的。因此,考虑到这一点,让我们完成它。

在服务器上...

  1. 为该选项创建一个新文件AuthenticationMethods
    sudo {editor of choice} /etc/ssh/sshd_config.d/two_key.conf
    
    笔记:请务必{editor of choice}用您选择的编辑器进行替换。
  2. 将这一行添加到文件:
    AuthenticationMethods publickey,publickey 
    
  3. 保存文件并重新启动 OpenSSH 服务器:
    sudo service sshd restart 
    
  4. 确保您的两个(或所有)公钥均已正确添加到~/.ssh/authorized_keys
  5. 从另一台机器连接:
    ssh -i /first/key -i /second/key user@host 
    

这里的所有都是它的

相关内容