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

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


当前回答

要在Ubuntu上查看密钥,只需在终端上输入以下命令:

ssh-add - l

你会得到这样的输出: 2568 0j:20:4b:88:a7:9t:wd:19:f0:d4:4y:9g:27:cf:97:23 yourName@ubuntu (RSA)

如果你得到一个错误,比如;无法打开到您的身份验证代理的连接。 这意味着ssh-agent没有运行。你可以用以下命令启动/运行它: ssh-agent bash(感谢评论中的@Richard),然后重新运行ssh-add -l

其他回答

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

投票最多的答案是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.

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

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

/root/.ssh
/root/.ssh/authorized_keys
$ ssh-add -l 

也适用于Mac OS X v10.8 (Mountain Lion) - v10.10 (Yosemite)。

它还支持-E选项来指定指纹格式,因此在需要MD5的情况下(它经常被使用,例如GitHub),只需在命令中添加-E MD5。

执行以下命令获取SSH密钥的SHA256指纹(-l表示“列表”,而不是创建新密钥,-f表示“文件名”):

$ ssh-keygen -lf /path/to/ssh/key

例如,在我的机器上,我运行的命令是(使用RSA公钥):

$ ssh-keygen -lf ~/.ssh/id_rsa.pub
2048 00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff /Users/username/.ssh/id_rsa.pub (RSA)

要使用更新版本的ssh-keygen获取GitHub (MD5)指纹格式,请运行:

$ ssh-keygen -E md5 -lf <fileName>

附加信息:

Ssh-keygen -lf也适用于known_hosts和authorized_keys文件。

要查找Linux/Unix/OS X系统上的大部分公钥,请运行

$ find /etc/ssh /home/*/.ssh /Users/*/.ssh -name '*.pub' -o -name 'authorized_keys' -o -name 'known_hosts'

(如果你想查看其他用户的homedirs内部,你必须是root或sudo。)

ssh-add -l非常类似,但是列出了添加到代理的密钥的指纹。(OS X用户请注意,通过Keychain实现神奇的无密码SSH与使用SSH -agent是不同的。)

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

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

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

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

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