简短版本:
Is there any way to set up automatic public-key-based ssh authentication from one Linux account to two different Github accounts?
我有两个 Github 帐户,一个是工作帐户,一个是个人帐户,我想将它们完全分开。
我已经在我的工作 Github 帐户中设置了自动 ssh 身份验证(使用我的 ~/.ssh/id_rsa.pub)。它工作正常。
当我尝试将相同的 ssh key 添加到我的个人 Github 帐户时,我收到“ key 已在使用中”的错误消息。
编辑:好的,我想可以通过
~/.ssh/config
中的适当设置来做我想做的事情。 ,但我还没有弄清楚这些应该是什么。一方面,我不清楚如何为同一主机( User
)指定两个不同的身份验证详细信息( IdentityFile
, github.com
),一旦我这样做了,我不知道 git 如何知道哪个我这样做时要呈现的两个键git push
.
最佳答案
您需要创建两组(公钥/私钥) key ,每个帐户一组。
您可以通过 ssh 配置文件引用它们,详见“GitHub: Multiple account setup”/
#Account one
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile /c/Users/yourname/.ssh/id_rsa
User git
#Account two
Host ac2.github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile /c/Users/yourname/.ssh/id_rsa_ac2
User git
关于github - 如何为来自同一个 ssh 客户端的两个单独的 GitHub 帐户设置身份验证?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14678618/