如何管理在GIT的两个不同私有存储库上使用的多个ssh密钥 [英] How do I manage multiple ssh keys to be used on two different private repository in GIT
问题描述
我在git上有两个私人存储库,并且在'Deploy keys'部分添加了其中的每个密钥,但事情是现在我遇到了麻烦,Git在我的机器上识别我的kyes ..我有两个公共/两个存储库的私人配对密钥... id_rsa.pub,id_rsa和id_rsa2.pub,id_rsa2。
从一个项目中,它运行良好,而从另一个项目不工作推或拉,它甚至不认识我的密码,似乎从任何项目我是Git总是使用id_rsa.pub文件。
为了清楚我的问题,我如何指定要基于项目进行配置的键,如我在Project'X'中使用id_rsa.pub而If我在'Y'项目中使用id.rsa2.pub
任何解决方案?
我在〜/ .ssh / config中有这个$ / $>
$ / $> b$ b
主机github-as-id1
HostName github.com
用户git
IdentityFile / home / me /。 ssh / _id_rsa
IdentitiesOnly是
Host github-as-id2
HostName github.com
User git
IdentityFile /home/me/.ssh/id_rsa2
IdentitiesOnly yes
然后在我的.git / config项目中我很喜欢
[remoteorigin]
url = ssh://git@github-as-id1/user/project.git
fetch = + refs / heads / *:refs / remotes / origin / *
用户名在那里两次。我认为你可以从.git / config中删除git @,或者从.ssh / config中删除 User git
I have two private repositories on git and I have added key on each of them on the 'Deploy keys' section, but the thing is now I am having trouble Git recognizing my kyes on my machine.. I have two public/private pair key for both of repositories... id_rsa.pub, id_rsa and id_rsa2.pub, id_rsa2.
From one project it works good, while from the other one it does not work push or pull, it does not even recognise my password, seems like from any project I am Git is using always id_rsa.pub file.
To make it clear my question is, How can I specify keys to be configured based on projects, like if I am in Project 'X' use id_rsa.pub while If I am in 'Y' project use id.rsa2.pub
Any solution?
If these repositories are not on github, adjust accordingly...
I have this in my ~/.ssh/config
Host github-as-id1
HostName github.com
User git
IdentityFile /home/me/.ssh/_id_rsa
IdentitiesOnly yes
Host github-as-id2
HostName github.com
User git
IdentityFile /home/me/.ssh/id_rsa2
IdentitiesOnly yes
then in my .git/config in the project I ahve
[remote "origin"]
url = ssh://git@github-as-id1/user/project.git
fetch = +refs/heads/*:refs/remotes/origin/*
The username is there twice. I think you could get rid of either "git@" from .git/config or User git
from .ssh/config
这篇关于如何管理在GIT的两个不同私有存储库上使用的多个ssh密钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!