【问题标题】:Setting up SSH keys for GitHub为 GitHub 设置 SSH 密钥
【发布时间】:2020-04-18 07:01:38
【问题描述】:

我正在关注these instructions,了解如何设置 SSH 密钥以用于 GitHub。

说明会告诉您删除当前的 .ssh 目录并在该 .ssh 目录中创建新密钥。我无法执行此操作,因为我的 id_dsa.pub 中已经有我需要用于其他服务器的密钥。

是否可以为 GitHub 设置 SSH,同时保留我已经保存在 .ssh 中的密钥?或者还有其他方法可以为 GitHub 设置 SSH?

【问题讨论】:

    标签: ssh github


    【解决方案1】:

    您可以重复使用目录中已有的密钥对,也可以创建一个专门供 GitHub 使用的新密钥对。如果您决定不使用默认对,则需要修改 ~/.ssh/config 文件并为 GitHub 添加主机定义,将其指向新的密钥文件。因此,如果您的新密钥对是 github_rsagithub_rsa.pub,请将这些行放入 /.ssh/config

    Host github.com
        HostName github.com
        User git
        IdentityFile ~/.ssh/github_rsa
    

    现在,每当您对git@github.com 执行拉取或推送操作时,都将使用备用身份文件。

    【讨论】:

      【解决方案2】:

      您可以生成具有特定名称的密钥,例如:

      ssh-keygen -t rsa -f ~/.ssh/id_rsa_github -C "your_email@youremail.com"
      

      然后您可以在~/.ssh/config 文件中为单独的服务器指定此密钥:

      Host *github.com
        IdentityFile ~/.ssh/id_rsa_github
        User git
      

      请参阅man sshman ssh_config 了解更多详情。

      【讨论】:

      • User 需要设置为 git - 我已经进行了更改。
      • 我没有找到配置文件
      【解决方案3】:

      确保你在全局配置中有这个:

      git config --global credential.helper osxkeychain
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-06-07
        • 1970-01-01
        • 2023-03-07
        • 2022-09-23
        • 2020-03-01
        • 1970-01-01
        • 2016-01-19
        • 2018-07-14
        相关资源
        最近更新 更多