2013-05-28 25 views
1

当连接到该主机上的不同git存储库时,我想为同一主机使用不同的rsa密钥。用于同一个远程主机的git的不同RSA密钥

例如,我有在example.com 2个git仓库:

[email protected]:rep1 

[email protected]:rep2 

使用2个不同的RSA密钥的典型方法是为不同的主机 的〜/ .ssh /配置:

Hostname example.com 
User git 
IdentityFile ~/.ssh/key1 

这不适用于我,因为这两个存储库托管在同一主机上。

你有什么建议吗?

回答

2

可以使用Host关键字:

Host host1 
HostName git.example.com 
User git 
IdentityFile ~/.ssh/key1 

Host host2 
HostName git.example.com 
User git 
IdentityFile ~/.ssh/key2 

然后用ssh host1ssh host2而不是使用完整的主机名。

+0

很好的建议,但我会缩进所有属于给定的'主机'定义的行,以使其更清晰 – mvp

+0

Thx的答案,但我如何添加我的git远程现在? –

+0

@NilsZiehn:使用'ssh:// host1/rep1'和'ssh:// host2/rep2'作为URL。 (我更改了主机标识符以使其更具可读性)。 – liori