多个GitHub帐户&;SSH配置
我在获取两个不同的SSH密钥/GitHub帐户时遇到了一些问题。我有以下设置: 使用多个GitHub帐户&;SSH配置,ssh,github,ssh-keys,Ssh,Github,Ssh Keys,我在获取两个不同的SSH密钥/GitHub帐户时遇到了一些问题。我有以下设置: 使用git@github.com:accountname 使用git@github.com:其他帐户 每个帐户都有自己的SSH密钥。已经添加了两个SSH密钥,并且我已经创建了一个配置文件。但是我不相信配置文件是正确的。我不太确定如何指定使用git@github.com:accountname应使用id\u rsa和git@github.com:其他帐户应使用id\u rsa\u其他帐户 在~/.ssh/config中
git@github.com:accountname
使用git@github.com:其他帐户
每个帐户都有自己的SSH密钥。已经添加了两个SSH密钥,并且我已经创建了一个配置文件。但是我不相信配置文件是正确的。我不太确定如何指定使用
git@github.com:accountname
应使用id\u rsa
和git@github.com:其他帐户
应使用id\u rsa\u其他帐户
在~/.ssh/config
中使用IdentityFile
参数:
Host github.com
HostName github.com
IdentityFile ~/.ssh/github.rsa
User petdance
Host proj1.github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/proj1.id_rsa
在
~/.ssh/config
中使用IdentityFile
参数:
Host github.com
HostName github.com
IdentityFile ~/.ssh/github.rsa
User petdance
Host proj1.github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/proj1.id_rsa
安迪·莱斯特的回答是准确的,但我发现我需要采取一个重要的额外步骤来实现这一点。在尝试设置两个配置文件时,一个用于个人,一个用于工作,我的
~/.ssh/config
大致如下:
Host me.github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/me_rsa
Host work.github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/work_rsa
直到我做了一个ssh添加~/.ssh/work\u rsa
之后,我的工作配置文件才生效。之后,到github的连接使用了正确的配置文件。以前,它们默认使用第一个公钥
对于,在使用ssh add
时无法打开与身份验证代理的连接,请检查:
安迪·莱斯特的回答是准确的,但我发现我需要采取一个重要的额外步骤来实现这一点。在尝试设置两个配置文件时,一个用于个人,一个用于工作,我的
~/.ssh/config
大致如下:
Host me.github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/me_rsa
Host work.github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/work_rsa
直到我做了一个ssh添加~/.ssh/work\u rsa
之后,我的工作配置文件才生效。之后,到github的连接使用了正确的配置文件。以前,它们默认使用第一个公钥
对于,在使用ssh add
时无法打开与身份验证代理的连接,请检查:
我发布了我用来处理这些问题的技巧我发布了我用来处理这些问题的技巧我最近不得不这样做,并且必须筛选所有这些答案和他们的评论,最终将信息拼凑在一起,因此为了您的方便,我将把它们全部放在这里:
步骤1:ssh密钥
创建您需要的任何密钥对。在本例中,我将我的名字命名为default/original'id_rsa'(这是默认名称),并将我的新名字命名为'id_rsa-work':
ssh-keygen -t rsa -C "stefano@work.com"
步骤2:ssh配置
通过创建/修改~/.ssh/config设置多个ssh配置文件。请注意略有不同的“主机”值:
# Default GitHub
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
# Work GitHub
Host work.github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_work
步骤3:ssh添加
你可能需要也可能不需要这样做。要检查,请通过运行以下命令列出身份指纹:
$ ssh-add -l
2048 1f:1a:b8:69:cd:e3:ee:68:e1:c4:da:d8:96:7c:d0:6f stefano (RSA)
2048 6d:65:b9:3b:ff:9c:5a:54:1c:2f:6a:f7:44:03:84:3f stefano@work.com (RSA)
如果您的条目不存在,请运行:
ssh-add ~/.ssh/id_rsa_work
步骤4:测试
为了测试您是否正确完成了这一切,我建议进行以下快速检查:
$ ssh -T git@github.com
Hi stefano! You've successfully authenticated, but GitHub does not provide shell access.
$ ssh -T git@work.github.com
Hi stefano! You've successfully authenticated, but GitHub does not provide shell access.
注意,您必须根据要使用的密钥/标识更改主机名(github/work.github)。但是现在你应该可以走了!:) 我最近不得不这样做,并且必须筛选所有这些答案和他们的评论,最终将信息拼凑在一起,因此为了您的方便,我将把它们全部放在这里的一篇帖子中:
步骤1:ssh密钥
创建您需要的任何密钥对。在本例中,我将我的名字命名为default/original'id_rsa'(这是默认名称),并将我的新名字命名为'id_rsa-work':
ssh-keygen -t rsa -C "stefano@work.com"
步骤2:ssh配置
通过创建/修改~/.ssh/config设置多个ssh配置文件。请注意略有不同的“主机”值:
# Default GitHub
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
# Work GitHub
Host work.github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_work
步骤3:ssh添加
你可能需要也可能不需要这样做。要检查,请通过运行以下命令列出身份指纹:
$ ssh-add -l
2048 1f:1a:b8:69:cd:e3:ee:68:e1:c4:da:d8:96:7c:d0:6f stefano (RSA)
2048 6d:65:b9:3b:ff:9c:5a:54:1c:2f:6a:f7:44:03:84:3f stefano@work.com (RSA)
如果您的条目不存在,请运行:
ssh-add ~/.ssh/id_rsa_work
步骤4:测试
为了测试您是否正确完成了这一切,我建议进行以下快速检查:
$ ssh -T git@github.com
Hi stefano! You've successfully authenticated, but GitHub does not provide shell access.
$ ssh -T git@work.github.com
Hi stefano! You've successfully authenticated, but GitHub does not provide shell access.
注意,您必须根据要使用的密钥/标识更改主机名(github/work.github)。但是现在你应该可以走了!:) 我曾经
Host github.com
HostName github.com
IdentityFile ~/.ssh/github_rsa
User abc@gmail.com
天气很好
在.ssh/config文件中为不同用户名的不同rsa密钥使用上述设置
Host github.com
HostName github.com
IdentityFile ~/.ssh/github_rsa
User abc@gmail.com
天气很好
在.ssh/config文件中为不同用户名的不同rsa密钥使用上述设置。假设
alice
是一个github.com用户,拥有两个或多个私有存储库repoN
。
在本例中,我们将使用两个名为repo1
和repo2
https://github.com/alice/repo1
https://github.com/alice/repo2
您需要在不输入密码的情况下从这些存储库中提取密码,可能是在一台服务器上,也可能是在多台服务器上。
例如,您希望执行git pull origin master
,并且希望在不要求密码的情况下执行此操作
您不喜欢与ssh代理打交道,您已经发现(或现在正在发现)关于~/.ssh/config
一个文件,该文件让您的ssh客户端根据主机名和用户名知道要使用什么私钥,其中有一个简单的配置条目,如下所示:
Host github.com
HostName github.com
User git
IdentityFile /home/alice/.ssh/alice_github.id_rsa
IdentitiesOnly yes
[remote "origin"]
url = "ssh://git@github.com/alice/repo1.git"
[remote "origin"]
url = git@github.com-account1:invitedByUserName/gfs.git
因此,您继续创建了(alice\u github.id\u rsa,alice\u github.id\u rsa.pub)
密钥对,然后您还访问了存储库的.git/config
文件,并将远程源文件的url修改为类似以下内容:
Host github.com
HostName github.com
User git
IdentityFile /home/alice/.ssh/alice_github.id_rsa
IdentitiesOnly yes
[remote "origin"]
url = "ssh://git@github.com/alice/repo1.git"
[remote "origin"]
url = git@github.com-account1:invitedByUserName/gfs.git
最后,您转到了存储库Settings>deploykeys
部分,添加了alice\u github.id\u rsa.pub
此时,您可以在不输入密码的情况下执行git pull origin master
但是第二个存储库呢?
因此,您的本能是抓住该键并将其添加到repo2
的Deplo中
[remote "origin"]
url = git@github.com-account1:account1/gfs.git
[remote "origin"]
url = git@github.com-account1:invitedByUserName/gfs.git
[remote "origin"]
url = git@github.com-account2:account2/gfs.git
git config user.name "account1"
git config user.email "account1@domain.com"
git config user.name "account2"
git config user.email "acccount2@doamin.com"