【问题标题】:Show SSH key file in Git Bash在 Git Bash 中显示 SSH 密钥文件
【发布时间】:2019-08-04 07:45:32
【问题描述】:

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

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

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

【问题讨论】:

    标签: git


    【解决方案1】:

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

    【讨论】:

    • 这在没有默认命令行 ssh 客户端运行的 Windows 上如何工作?
    • @HansHarhoff 在 Windows 10 中,PowerShell 包括 OpenSSH 客户端。只需确保已激活此可选功能(在 Windows 中搜索“管理可选功能”)。
    • Git for Windows 通常包含自己的 SSH 客户端,应该可以从 Git Bash 获得。
    【解决方案2】:

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

    $ git-gui
    

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

    【讨论】:

    • 感谢简单易行的解决方案!
    【解决方案3】:

    这个命令对我有用:

    cat ~/.ssh/id_rsa.pub
    

    【讨论】:

    • 这仅适用于您在默认位置使用默认 RSA 密钥的情况。如果您的密钥有其他名称或您正在使用其他类型(如 ED25519),则此方法不起作用。
    猜你喜欢
    • 2017-07-13
    • 2012-05-05
    • 2013-06-22
    • 1970-01-01
    • 2020-05-19
    • 2020-09-19
    • 1970-01-01
    • 2021-05-13
    • 2015-09-23
    相关资源
    最近更新 更多