我有两个不同的帐户,我必须将更改上传到,这里的问题是 GitHub 帐户和 Bitbucket 帐户具有不同的电子邮件地址,所以我尝试配置多个 ssh key 以继续提交、推送和拉取更改分别来自 Github 和 Bitbucket。
我尝试通过运行生成两个不同的 ssh key :
ssh-keygen -t rsa -C "My.CorporateAddress@company.com"
然后,当被要求输入保存 key 的文件时,我添加了这个:
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 帐户,它们都配置了不同的电子邮件地址。
我究竟做错了什么?您的反馈将不胜感激!
最佳答案
要测试您的不同 key ,您应该键入:
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”。
关于macos - 如何为 Github 帐户和 Bitbucket 公司帐户添加多个 SSH key ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58496708/