Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
同一远程主机上git的不同RSA密钥_Git_Rsa - Fatal编程技术网

同一远程主机上git的不同RSA密钥

同一远程主机上git的不同RSA密钥,git,rsa,Git,Rsa,当连接到此主机上的不同git存储库时,我希望对同一主机使用不同的rsa密钥 例如,我在example.com上有两个git存储库: git@git.example.com:rep1 及 使用两个不同RSA密钥的典型方法是针对不同的主机 ~/.ssh/config: Hostname example.com User git IdentityFile ~/.ssh/key1 这对我不起作用,因为两个存储库托管在同一台主机上 您有什么建议吗?您可以使用Host关键字: Host host1 Ho

当连接到此主机上的不同git存储库时,我希望对同一主机使用不同的rsa密钥

例如,我在example.com上有两个git存储库:

git@git.example.com:rep1

使用两个不同RSA密钥的典型方法是针对不同的主机 ~/.ssh/config:

Hostname example.com
User git
IdentityFile ~/.ssh/key1
这对我不起作用,因为两个存储库托管在同一台主机上


您有什么建议吗?

您可以使用
Host
关键字:

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

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

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

好建议,但我会缩进属于给定
host
定义的所有行,以便更清楚地找到答案,但是我现在如何添加git remote?@NilsZiehn:Use
ssh://host1/rep1
ssh://host2/rep2
作为URL。(我更改了主机标识符以使其更具可读性)。
Host host1
HostName git.example.com
User git
IdentityFile ~/.ssh/key1

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