如何为来自同一个 ssh 客户端的两个单独的 GitHub 帐户设置身份验证? [英] How to set up authentication for two separate GitHub accounts from same ssh client?

查看:17
本文介绍了如何为来自同一个 ssh 客户端的两个单独的 GitHub 帐户设置身份验证?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简短版本:

有什么方法可以设置从一个 Linux 帐户到两个不同的 Github 帐户的基于公钥的自动 ssh 身份验证?

Is there any way to set up automatic public-key-based ssh authentication from one Linux account to two different Github accounts?

<小时>

我有两个 Github 帐户,一个是工作帐户,一个是个人帐户,我想将它们完全分开.


I have two Github accounts, a work one and a personal one, which I want to keep entirely separate.

我已经在我的工作 Github 帐户中设置了自动 ssh 身份验证(使用我的 ~/.ssh/id_rsa.pub).它工作正常.

I already set up automatic ssh authentication (using my ~/.ssh/id_rsa.pub) in my work Github account. It works fine.

当我尝试将相同的 ssh 密钥添加到我的个人 Github 帐户时,我收到密钥已被使用"的错误消息.

When I try to add the same ssh key to my personal Github account, I get the error that the "key is already in use."

好的,我想人们可以通过 ~/.ssh/config 中的适当设置来做我想做的事情,但我还没有弄清楚这些应该是什么.一方面,我不清楚如何为同一主机 (github.com) 指定两个不同的身份验证详细信息(UserIdentityFile)),一旦我这样做了,当我执行 git push 时,我不知道 git 如何知道要呈现两个键中的哪一个.

OK, I guess that one may be able to do what I want to do through suitable settings in ~/.ssh/config, but I have not yet figured out what these should be. For one thing, it's not clear to me how to specify two different authentication details (User, IdentityFile) for the same host (github.com), and once I do, I don't see how git knows which of the two keys to present when I do git push.

推荐答案

您需要创建两组(公钥/私钥)密钥,每个帐户一个.

You need to create two sets of (public/private) keys, one for each account.

您可以通过 ssh 配置文件引用它们,详见GitHub:多账户设置"/

You can reference them through an ssh config file, as detailed in "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

这篇关于如何为来自同一个 ssh 客户端的两个单独的 GitHub 帐户设置身份验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆