SSH 代理从哪里获取它用于密钥的名称?

SSH 代理从哪里获取它用于密钥的名称?

我不太明白 SSH 代理如何引用它正在使用的密钥。

我有四个 SSH 密钥,带有以下注释:

$ tail -n +1 *.pub
==> github_id_ed25519.pub <==
ssh-ed25519 ... mygithubusername@myhost

==> id_ecdsa.pub <==
ecdsa-sha2-nistp521 ... me@myhost

==> id_ed25519.pub <==
ssh-ed25519 ... me@myhost

==> id_rsa.pub <==
ssh-rsa ... me@myhost

我将这些密钥添加到 SSH 代理(带有确认-c选项):

$ ssh-add -c github_id_ed25519 id_ecdsa id_ed25519 id_rsa
Enter passphrase for github_id_ed25519 (will confirm each use): 
Identity added: github_id_ed25519 (mygithubusername)
The user must confirm each use of the key
Identity added: id_ecdsa (id_ecdsa)
The user must confirm each use of the key
Identity added: id_ed25519 (me@myhost)
The user must confirm each use of the key
Identity added: id_rsa (id_rsa)
The user must confirm each use of the key

我列出了所有添加的键:

$ ssh-add -l
256  SHA256:... mygithubusername (ED25519)
521  SHA256:... id_ecdsa (ECDSA)
256  SHA256:... me@myhost (ED25519)
4096 SHA256:... id_rsa (RSA)

SSH 代理从哪里获取用于引用密钥的名称?

似乎使用:

  1. 密钥文件中的完整注释(针对一个密钥)
  2. 密钥文件中注释的某些部分(对于一个密钥)
  3. 密钥文件的文件名(两个密钥)

很难理解这一点。使用密钥的文件名将是最直接的,但现在它只是一团糟。目前,每次我使用 SSH 登录并收到确认对话框时,很难弄清楚它实际上尝试使用哪个密钥。

答案1

ssh-add尝试读取私钥文件中的注释。如果失败,它将使用文件名作为进一步提示的注释:

ssh-add.c:添加文件() :

if (comment == NULL || *comment == '\0')
    comment = xstrdup(filename);

我怀疑使用文件名作为注释的任何身份都没有最初与密钥一起保存的注释,即使是手动编辑到民众稍后生成密钥文件。手册ssh-keygen页暗示无法更改或添加注释私人的任何未弃用的密钥格式的密钥文件:

 -c      Requests changing the comment in the private and public key files.  This
         operation is only supported for RSA1 keys.

相关内容