我需要为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

其他回答

要在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.

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

在这里从AWS论坛复制内容,因为我发现它对我的用例很有用——我想检查哪些密钥与我导入AWS的密钥匹配

Openssl pkey -in ~/.ssh/ec2/primary.使用实例openssl md5 -c . pem -pubout -outform DER |

地点:

主要的Pem是要检查的私钥

注意,这与ssh-keygen计算的指纹不同。

要在第一次连接之前检查远程SSH服务器,可以查看www.server-stats.net/ssh/以查看服务器的所有SHH密钥,以及何时知道密钥。

这与SSL证书不同,但绝对是第一次连接到任何SSH服务器之前必须做的事情。

较新的SSH命令将指纹列为SHA256密钥。

例如:

ssh-keygen -lf ~/.ssh/id_dsa.pub 
1024 SHA256:19n6fkdz0qqmowiBy6XEaA87EuG/jgWUr44ZSBhJl6Y (DSA)

如果您需要将其与旧指纹进行比较,还需要指定使用MD5指纹哈希功能。

ssh-keygen -E md5 -lf ~/.ssh/id_dsa.pub
2048 MD5:4d:5b:97:19:8c:fe:06:f0:29:e7:f5:96:77:cb:3c:71 (DSA)

同样可用:-E sha1

更新……是的……是的……我知道…SSH的DSA密钥不应该再使用,应该使用较旧的RSA密钥或较新的黄道密钥。

致那些一直编辑我在上面使用的命令的“管理员”。别再改了!您使命令和产生的输出不匹配!