首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在github帐户中使用的SSH密钥之间切换

问如何在github帐户中使用的SSH密钥之间切换
EN

Stack Overflow用户
提问于 2021-10-18 21:04:27
回答 1查看 724关注 0票数 1

我有两把SSH钥匙。一个是我公司的github帐户,另一个是我的个人github帐户。在我为我的个人帐户创建另一个SSH密钥之前,我的公司帐户SSH密钥一直运行良好。我最后创建的SSH密钥对是为我的个人帐户创建的,它运行得很好。现在,我正试图推到我的公司帐户,但我收到一条错误信息。有什么方法可以同时使用SSH密钥或在它们之间切换吗?我将分享我的配置文件。第一个是我公司帐户的原始SSH密钥。

代码语言:javascript
复制
Host *
  AddKeysToAgent yes
  UseKeychain yes
  IdentityFile ~/.ssh/id_rsa

Host github.com
  HostName github.com
  AddKeysToAgent yes
  UseKeychain yes
  IdentityFile ~/.ssh/id_ed25519
  IdentitiesOnly yes
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-10-18 21:24:45

Git详细介绍了这个主题,包括为SSH和HTTPS。对于SSH,FAQ在您的~/.ssh/config中建议如下

代码语言:javascript
复制
# This is the account for author on git.example.org.
Host example_author
    HostName git.example.org
    User git
    # This is the key pair registered for author with git.example.org.
    IdentityFile ~/.ssh/id_author
    IdentitiesOnly yes
# This is the account for committer on git.example.org.
Host example_committer
    HostName git.example.org
    User git
    # This is the key pair registered for committer with git.example.org.
    IdentityFile ~/.ssh/id_committer
    IdentitiesOnly yes

然后,它指出您需要更改您的URL:

然后,您可以调整您的推URL使用git@example_author或git@example_committer而不是git@example.org (例如,git remote set-url git@example_author:org1/project1.git)。

显然,在您的示例中,您希望使用github.com代替git.example.org,并且可能希望对主机名使用不同的条目。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69622565

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档