How to setup multiple ssh identities for single hg repository?

霸气de小男生 提交于 2019-12-04 12:24:05

问题


I am using ssh publickey authentication for my mercurial repository. So I have:

[ui]
ssh = ssh -i ~/.ssh/id_rsa -C 

in my .hgrc. This works fine and allows me to push/pull to an ssh-authenticated repo. However, I want to be able to push/pull to another repo that requires a different identity. How can I configure my .hgrc file so the identity is tied to a particular path. I guess I'd want something like:

[ui]
one.prefix = someserver.com
one.ssh = ssh -i ~/.ssh/id_rsa -C
two.prefix = otherserver.com
two.ssh = ssh -i ~/.ssh/otherid_rsa -C

回答1:


In your ~/.ssh/config, add

Host someserver.com
IdentityFile ~/.ssh/id_rsa

Host otherserver.com
IdentityFile ~/.ssh/otherid_rsa

and anybody (including hg and interactive use) using ssh to connect to hosts someserver.com or otherserver.com will use the specified identity files.

See ssh_config for other options.




回答2:


You do it using ssh's own tool: ssh-agent.

$ eval $(ssh-agent)
$ ssh-add ~/.ssh/id_rsa
$ ssh-add ~/.ssh/otherid_rsa

Then you don't need ssh identify related anything in your .hgrc's [ui] section at all.

Alternately you could do:

[ui]
ssh = ssh -i ~/.ssh/id_rsa -i ~/.ssh/otherid_rsa -C

but ssh-agent is useful in so many way's it's worth putting it your login scripts and calling it a day.



来源:https://stackoverflow.com/questions/4833289/how-to-setup-multiple-ssh-identities-for-single-hg-repository

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!