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

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

问题描述

我在让两个不同的 SSH 密钥/GitHub 帐户协同工作时遇到了一些麻烦.我有以下设置:

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

使用 git@github.com:accountname

使用 git@github.com:anotheraccount

每个帐户都有自己的 SSH 密钥.两个 SSH 密钥都已添加,并且我创建了一个配置文件.我不相信配置文件是正确的.我不太确定如何指定使用 git@github.com:accountname 访问的 repos 应该使用 id_rsagit@github.com:anotheraccount 应该使用 id_rsa_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 的回答是准确的,但我发现我需要执行一个重要的额外步骤才能使其发挥作用.在尝试设置两个配置文件,一个用于个人,一个用于工作,我的 ~/.ssh/config 大致如下:

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

直到我做了一个ssh-add ~/.ssh/work_rsa,我的工作资料才被接受.之后到 github 的连接使用了正确的配置文件.以前他们默认使用第一个公钥.

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.

对于在使用 ssh-add无法打开到您的身份验证代理的连接
检查:https://stackoverflow.com/a/17695338/1760313

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

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