ssh-key - 多个 github 账号,怎样配置对应的 SSH key

【字号: 日期:2023-10-24浏览:29作者:雯心

问题描述

我有多个 github 账号,分别设置了不同的 SSH key,one_rsa 和 two_rsa那么,在对 git 项目进行操作时,如何保证不冲突呢?

问题解答

回答1:

使用 ssh config(ssh_config Recipes). 在 .ssh 目录下新建一个 config 文件,配置对应不同 Host 使用不同的 key. 例如:

Host gitcafe.xxxHostName gitcafe.comUser gitIdentityFile ~/.ssh/id_rsa_gitcafe_xxxHost gitcafe.yyyHostName gitcafe.comUser gitIdentityFile ~/.ssh/id_rsa_gitcafe_yyyHost github.xxxHostName github.comIdentityFile ~/.ssh/id_rsa_github_xxx# 此行是代理配置,请无视ProxyCommand ~/.ssh/socksproxywrapper.sh %h %p

比如 id_rsa_github_xxx 是你在 github 上 xxx 用户的 key, 就可以使用

git clone git@github.xxx:xxx/project.git

这样的方式来拉取 github 上的项目。

回答2:

ssh 可以配置host,在~/.ssh/config里面吧

相关文章: