【问题标题】:How can I add multiple SSH keys for a Github account and a Bitbucket corporate account如何为 Github 帐户和 Bitbucket 公司帐户添加多个 SSH 密钥
【发布时间】:2020-02-18 03:46:59
【问题描述】:

我有两个不同的帐户,我必须将更改上传到,这里的问题是 GitHub 帐户和 Bitbucket 帐户有不同的电子邮件地址,所以我正在尝试配置多个 ssh 密钥以继续提交、推送并分别从 Github 和 Bitbucket 拉取更改。

我尝试通过运行生成两个不同的 ssh 密钥:

    ssh-keygen -t rsa -C "My.CorporateAddress@company.com"    

然后,当被要求输入保存密钥的文件时,我添加以下内容:

    Enter file in which to save the key (/Users/myUser/.ssh/id_rsa): /Users/myUser/.ssh/id_rsa_github

我对 bitbucket 执行相同的步骤。

然后我生成一个名为 config 的文件并通过添加来编辑它:

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


    Host bitbucket
    HostName corporate-address.com
    User git
    IdentityFile ~/.ssh/id_rsa_bitbucket

但是当我跑步时:

    ssh -T git@bitbucket

或者:

    ssh -T git@github

并尝试对其中任何一个提出拉取请求,我收到以下错误:

GITHUB ERROR:

git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

---------------------------------------------------
---------------------------------------------------
BITBUCKET ERROR:

git@bitbucket.corporate.companyName.com: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

出于安全原因,我省略了公司名称。

我想要实现的是可以同时使用我的工作 Bitbucket 帐户和我的个人 Github 帐户,它们配置了不同的电子邮件地址。

我做错了什么?您的反馈将不胜感激!

【问题讨论】:

    标签: macos github ssh bitbucket ssh-keys


    【解决方案1】:

    要测试您的不同密钥,您应该输入:

    ssh -Tv github
    ssh -Tv bitbucket
    

    无需添加用户。

    再试一次,old PEM format

    ssh-keygen -t rsa -C "xxx@yyyy.com" -m PEM -P "" -f ~/.ssh/id_rsa_github
    ssh-keygen -t rsa -C "another@yyyy.com" -m PEM -P "" -f ~/.ssh/id_rsa_bitbucket
    

    但请确保将您的公钥添加到您的帐户中。
    GitHub 示例:“Adding a new SSH key to your GitHub account”。

    【讨论】:

    • 谢谢,VonC,我一定会试试的,如果成功了,现在就给你
    • 不幸的是,它没有用,我仍然有同样的错误
    【解决方案2】:

    我终于能够配置我的两个 git 帐户,它们现在已经启动并运行了。

    我按照我找到的这个教程进行操作,效果非常好!

    Configuring Multiple SSH Keys on Mack

    【讨论】:

    • 您的意思是您的 ssh 密钥有密码吗?你需要运行 ssh-agent 吗?
    猜你喜欢
    • 2014-09-11
    • 1970-01-01
    • 2017-07-02
    • 1970-01-01
    • 1970-01-01
    • 2020-09-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多