我必须采取哪些措施才能使用SSH始终推送到两个Github帐户? [英] What steps must I take to consistently push to two Github accounts using SSH?

查看:121
本文介绍了我必须采取哪些措施才能使用SSH始终推送到两个Github帐户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I commit to Github for work and for personal use.  For the last two months I have consistently had trouble each and every time I switch github contexts.  Every night (and every morning) I run into error's pushing to or pulling form Github like this:

如果我可以得到推/拉工作正常(通常通过阅读关于SSH / Github / Git的StackOverflow帖子的一些迂回路径,并没有深入理解它们),当我从工作Github切换到家或恶习时,我立即再次遇到同样的问题。

我注意到唯一有趣的线索是在拒绝alexbollbach ,alexbollbach是我的工作Github帐户用户名。嗯,这导致我考虑〜/ .ssh / config ,其内容是:

ERROR: Permission to AlexanderBollbach/test.git denied to alexbollbach. fatal: Could not read from remote repository. Please make sure you have the correct access rights

If I can get the pushing/pulling to work properly (usually through some circuitous path of reading StackOverflow posts about SSH/Github/Git and not understanding them in any depth), I immediately run into the same problems again when I switch from work Github to home or vice versa.

我被告知这个文件有助于配置git的ssh尝试。但是我仍然不能在这个文件和git push错误之间建立联系,认为我是 alexbollbach 。事实上,我不知道ssh,我的密钥对和配置文件在任何意义上都与Github用户的概念有关。

The only interesting clue I have noticed is that in denied to alexbollbach, "alexbollbach" is my work Github account username. hmm, this leads me to consider ~/.ssh/config, whose contents are:

请帮忙。最好不要只是一个修复,但要澄清一下我没有抓住什么。我常常每周至少花两个小时处理这个问题。

Host * AddKeysToAgent yes UseKeychain yes IdentityFile ~/.ssh/id_rsa Host github.com User git Host helper HostName <work-domain-stuff> IdentityFile ~/.ssh/eng_rsa User eng

Git中的密钥是通过远程URL。

像这样改变这些URL:

The way you link a remote repo and different ssh keys in Git is through the remote url.
Change those urls like so:

 cd /path/to/my/work/repo
 git remote set-url origin workgh:myWorkLogin/myWorkrepo.git

 cd /path/to/my/perso/repo
 git remote set-url origin persgh:myPersoLogin/myPersorepo.git

请参阅作为一个完整的示例,如何从办公室计算机的个人GitHub回购工作中获得,该办公室计算机的SSH密钥已经添加到与工作相关的GitHub账户?
〜/ .ssh / config 会为每个网址引用正确的ssh密钥:

See "How to work on personal GitHub repo from office computer whose SSH key is already added to a work related GitHub account?" as a full example.
Your ~/.ssh/config will reference the right ssh key for each url:

# Personal GitHub
Host persgh
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_rsa_perso

# Work GitHub
Host workgh
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_rsa_work

不要使用 github.com 作为主机:使用主机密钥的特殊名称更加明确,并且表明这是您必须解析的ssh url通过〜/ .ssh / config 文件。

Don't use "github.com" as a "Host": using an special name for the Host key is more explicit and indicates this is an ssh url you have to resolve through a ~/.ssh/config file.

这篇关于我必须采取哪些措施才能使用SSH始终推送到两个Github帐户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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