2011-01-28 101 views
5

我爲我的mercurial存儲庫使用ssh publickey身份驗證。所以我有:如何爲單個hg存儲庫設置多個ssh身份?

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

在我的.hgrc中。這工作正常,並允許我推/拉到ssh認證回購。但是,我希望能夠推動/拉到另一個需要不同身份的回購。我怎樣才能配置我的.hgrc文件,使身份與特定的路徑相關聯。我想我想要的東西是這樣的:

[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 

回答

3

你使用ssh自己的工具:ssh-agent。

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

那麼你不需要在你的.hgrc[ui]部分在所有SSH識別相關的任何東西。

或者你可以這樣做:

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

但SSH代理是在如此多的方式有用的是這是值得把它你的登錄腳本,把它一天。

+1

我認爲它是`ssh = ssh -i〜/ .ssh/id_rsa -i〜/ .ssh/otherid_rsa -C`否則我們會得到一個ssh用法錯誤。 – 2014-12-08 17:03:45

8

在你~/.ssh/config,添加使用ssh連接到主機someserver.comotherserver.com將使用指定的身份文件

Host someserver.com 
IdentityFile ~/.ssh/id_rsa 

Host otherserver.com 
IdentityFile ~/.ssh/otherid_rsa 

和任何人(包括hg和交互使用)。

請參閱ssh_config其他選項。