标签:identity repos 内部使用 xxxx The 关联 表示 hub agent
github一把公钥只能用于一个github账户,如果想在同一主机上给两个属于不同账户的仓库提交时,必须在本地创建两对公/私钥匙,分别把两把公钥给两个帐号。
或者有时候,你公司内部使用的gitlab,同时你个人又有github,你想用同一个公钥将仓库分别提交到github和gitlab。
生成第一把公钥:
ssh-keygen -t rsa -C "kobe@email.com"
# 设置名称为id_rsa_kobe
Enter file in which to save the key ((/home/xxxx/.ssh/id_rsa)): id_rsa_kobe
#添加到SSH agent中
ssh-add id_rsa_kobe
制造第二把公钥:
ssh-keygen -t rsa -C "jordan@email.com"
# 设置名称为id_rsa_jordan
Enter file in which to save the key ((/home/xxxx/.ssh/id_rsa)): id_rsa_jordan
#添加到SSH agent中
ssh-add id_rsa_jordan
# 在.ssh目录下配置config文件:
Host kobe
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_kobe
Host jordan
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_jordan
ssh -T kobe
Hi kobe! You've successfully authenticated, but GitHub does not provide shel l access.
ssh -T ranpop
Hi jordan! You've successfully authenticated, but GitHub does not provide shel l access.
对于kobe帐号下的仓库:
git clone kobe:githubname/repository.git
(原地址是:git@github.com:githubname/repository.git,替换后应该是:kobe:githubname/repository.git)
对于ranpop帐号下的仓库:
git clone jordan::githubname/repository.git
(原地址是:git@github.com:githubname/repository.git,替换后应该是:jordan:githubname/repository.git)
# 如果已经使用原地址克隆过了,可以使用如下命令修改
git remote set-url origin kobe:githubname/repository.git
# 如果是本地新建的仓库,可以使用如下命令添加
git remote add origin jordan:githubname/repository.git
# 在.ssh目录下配置config文件:
Host github
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_kobe
Host gitlab
HostName gitlab.com
User git
IdentityFile ~/.ssh/id_rsa_kobe
ssh -T github
Hi kobe! You've successfully authenticated, but GitHub does not provide shel l access.
ssh -T gitlab
Welcome to GitLab, @kobe!
git remote add github github:githubname/repository.git
git remote add gitlab gitlab:githubname/repository.git
# 推送master分支到github
git push github master
# 推送master分支到gitlab
git push gitlab master
同一主机设置多个密钥与不同github账号关联,或同一主机同一密钥分别关联github和gitlab
标签:identity repos 内部使用 xxxx The 关联 表示 hub agent
原文地址:https://www.cnblogs.com/logchen/p/10543808.html