我需要为GitHub做SSH密钥审计,但我不确定如何找到我的RSA密钥指纹。我最初是按照指南在Linux上生成SSH密钥的。

我需要输入什么命令来查找我当前的RSA密钥指纹?


当前回答

这是我用来获取SSH密钥指纹以创建DigitalOcean液滴的shell函数:

fingerprint() {
    pubkeypath="$1"
    ssh-keygen -E md5 -lf "$pubkeypath" | awk '{ print $2 }' | cut -c 5-
}

把它放在你的~/。Bashrc,来源它,然后你可以得到指纹,如下所示:

$ fingerprint ~/.ssh/id_rsa.pub
d2:47:0a:87:30:a0:c0:df:6b:42:19:55:b4:f3:09:b9

其他回答

在Fedora上我找到~/。SSH,它告诉我密钥在

/root/.ssh
/root/.ssh/authorized_keys

有时您可以在~/中有一串键。ssh目录,不知道哪个匹配GitHub/Gitlab/etc显示的指纹。

下面介绍如何显示~/中所有密钥的密钥文件名和MD5指纹。ssh目录:

cd ~/.ssh
find . -type f -exec printf "\n{}\n" \; -exec ssh-keygen -E md5 -lf {} \;

(参数的含义请参见find命令的回答。

请注意,属于一个密钥的私有/公共文件具有相同的指纹,因此您将看到重复的指纹。

这是我用来获取SSH密钥指纹以创建DigitalOcean液滴的shell函数:

fingerprint() {
    pubkeypath="$1"
    ssh-keygen -E md5 -lf "$pubkeypath" | awk '{ print $2 }' | cut -c 5-
}

把它放在你的~/。Bashrc,来源它,然后你可以得到指纹,如下所示:

$ fingerprint ~/.ssh/id_rsa.pub
d2:47:0a:87:30:a0:c0:df:6b:42:19:55:b4:f3:09:b9

密钥对(私钥和公钥)将具有相同的指纹;因此,在你不记得哪个私钥属于哪个公钥的情况下,通过比较他们的指纹来找到匹配。

投票最多的答案是Marvin Vinto提供了一个公共SSH密钥文件的指纹。也可以查询对应的SSH私钥指纹,但需要较长的一系列步骤,如下图所示。

Load the SSH agent, if you haven't done so. The easiest way is to invoke $ ssh-agent bash or $ ssh-agent tcsh (or another shell you use). Load the private key you want to test: $ ssh-add /path/to/your-ssh-private-key You will be asked to enter the passphrase if the key is password-protected. Now, as others have said, type $ ssh-add -l 1024 fd:bc:8a:81:58:8f:2c:78:86:a2:cf:02:40:7d:9d:3c you@yourhost (DSA) fd:bc:... is the fingerprint you are after. If there are multiple keys, multiple lines will be printed, and the last line contains the fingerprint of the last loaded key. If you want to stop the agent (i.e., if you invoked step 1 above), then simply type `exit' on the shell, and you'll be back on the shell prior to the loading of ssh agent.

我没有添加新的信息,但希望这个答案对所有级别的用户都很清楚。

如果您的密钥在SSH代理中,最快的方法是:

$ ssh-add -L | ssh-keygen -E md5 -lf /dev/stdin

代理中的每个键将被打印为:

4096 MD5:8f:c9:dc:40:ec:9e:dc:65:74:f7:20:c1:29:d1:e8:5a /Users/cmcginty/.ssh/id_rsa (RSA)