87

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

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

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

4

3 回答 3

118

使用哪个 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是服务器接受的密钥。

于 2013-09-17T09:23:33.073 回答
63

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

$ git-gui

然后一个 GUI 应用程序正在执行,在 GUI 中,您只需单击帮助显示 SSH 密钥即可显示您的 SSH 密钥。

于 2016-08-31T04:53:40.067 回答
11

这个命令对我有用:

cat ~/.ssh/id_rsa.pub
于 2019-05-20T12:38:17.940 回答