如何验证RSA SSH公钥文件(id_rsa.pub)?


63

有没有我可以用来验证公用密钥(id_rsa.pub)的命令,仅用于验证格式

有时我添加了新的换行符,有时文件缺少ssh-rsa前缀,那么是否有验证命令?

Answers:


92

您可以ssh-keygen为此使用。尽管它的名字叫它比生成密钥还可以做很多事情:

dennis@lightning:~$ ssh-keygen -l -f .ssh/id_rsa.pub 
2048 68:df:b2:22:d8:43:5d:36:75:c1:d8:59:c0:8c:22:e8  Dennis Kaarsemaker (RSA)
dennis@lightning:~$ ssh-keygen -l -f foo.txt
foo.txt is not a public key file.

因此,我必须事先拥有指纹才能验证公钥?
Quazi Irfan

1
@QuaziIrfan不,您不需要指纹。的返回码ssh-keygen将告诉您它是否有效。
vidstige

1
不适用于带有密码的密钥:-(
vidstige '17

2
请注意,这也适用于包含多个键的文件,例如~/.ssh/authorized_keys
slhck

@QuaziIrfan指纹是“ ssh-keygen -l”输出的输出,用于显示给定pub / pri密钥文件的指纹
Devy
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.