多个GitHub帐户& SSH配置 [英] Multiple GitHub Accounts & SSH Config

查看:125
本文介绍了多个GitHub帐户& SSH配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在获取两个不同的SSH密钥/ GitHub帐户时遇到了一些麻烦,难以一起玩。我有以下设置:



通过 git@github.com:accountname



使用 git@github.com:anotheraccount



可从其他帐户访问Repos每个帐户都有自己的SSH密钥。两个SSH密钥都已添加,并且我创建了一个配置文件。我不相信配置文件是正确的。我不太清楚如何指定使用 git@github.com:accountname 访问的回购应使用 id_rsa git@github.com:anotheraccount 应该使用 id_rsa_anotheraccount

解决方案

安迪莱斯特的回答是准确的,但我发现了一个重要的额外步骤,我需要让这个工作。试图建立两个配置文件,一个用于个人用户,另一个用于工作,我的〜/ .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-add〜/ .ssh / work_rsa ,我的工作档案才得以实现。之后,连接到github使用正确的配置文件。 在使用 ssh时,无法打开与身份验证代理的连接 -add
检查:
https://stackoverflow.com/a/17695338 / 1760313


I'm having some trouble getting two different SSH keys/GitHub accounts to play well together. I have the following setup:

Repos accessible from one account using git@github.com:accountname

Repos accessible from another account using git@github.com:anotheraccount

Each account has its own SSH key. Both SSH keys have been added and I have created a config file. I don't believe the config file is correct though. I'm not quite sure how to specify that repos accessed using git@github.com:accountname should use id_rsa and git@github.com:anotheraccount should use id_rsa_anotheraccount.

解决方案

Andy Lester's response is accurate but I found an important extra step I needed to make to get this to work. In trying to get two profiles set up, one for personal and one for work, my ~/.ssh/config was roughly as follows:

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

My work profile didn't take until I did a ssh-add ~/.ssh/work_rsa. After that connections to github used the correct profile. Previously they defaulted to the first public key.

For Could not open a connection to your authentication agent when using ssh-add,
check: https://stackoverflow.com/a/17695338/1760313

这篇关于多个GitHub帐户& SSH配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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