在Git Bash中显示SSH密钥文件


71

如何查看Git Bash中使用了哪个SSH密钥文件?

我尝试了“ git config --get-all”,但收到错误消息

错误:参数数量错误;用法:git config [选项]

Answers:


99

使用哪个SSH密钥不是由Git决定的,而是由SSH客户端本身决定的。可以在中配置适当的密钥~/.ssh/config,也ssh可以尝试连接主机时找到的所有密钥。您可以通过使用标准SSH客户端连接到主机来查看哪个密钥最终成功。例如,当使用GitHub时:

ssh -v git@github.com

这会给你这样的东西:

[...]
debug1: Offering RSA public key: /home/me/.ssh/id_rsa
debug1: Authentications that can continue: publickey
debug1: Offering RSA public key: /home/me/.ssh/id_rsa2
debug1: Server accepts key: pkalg ssh-rsa blen ****
[...]

这告诉您密钥.../id_rsa2是服务器接受的密钥。


1
在没有默认命令行ssh客户端运行的Windows上,这如何工作?
HansHarhoff

@HansHarhoff在Windows 10中,PowerShell包含OpenSSH客户端。只要确保已激活此可选功能(在Windows中搜索“管理可选功能”)即可。
New3D

Git for Windows通常包括自己的SSH客户端,应该可以从Git Bash获得。
JanKrüger2

56

另一个解决方案,在最新的Git Bash中,您可以输入:

$ git-gui

然后将执行GUI应用程序,在GUI中,您只需单击“帮助” →“显示SSH密钥”以显示SSH密钥。


1
感谢您简单易用的解决方案!!
Praveen Kumar KS

6

这个命令对我有用:

cat ~/.ssh/id_rsa.pub
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.