GitHub:多账号设置 [英] GitHub: Multiple account setup

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

问题描述

我尝试了3个多小时,为github设置了多个帐户,并且非常疲倦。我尝试了几乎所有可能的方式在这里描述,github和文章,并没有一个工作。我对github和Unix也是新手。所以需要你的帮助来解决这个问题。下面是我在做什么



我正在使用Windows 7并为两个不同的账户设置了两个ssh密钥。


  1. id_rsa

  2. id_rsa_ac2

.ssh 用户目录并添加了以下代码

 #帐户一
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile /c/Projects/.ssh/id_rsa

#Account two
主机ac2.github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile /c/Projects/.ssh/id_rsa_ac2

现在我试图使用下面的代码添加远程代码:

  git远程添加源git@ac2.github.com:myaccount / my.git 

并按以下代码

  git push origin master 

但是,当我试图推动它是g iving me错误:
错误:myaccount / my.git被拒绝给{account}的权限。 //它在考虑默认用户帐户而不是用于ac2用户帐户
致命:无法从远程存储库读取



请确保您拥有正确的访问权限并存在存储库。



非常感谢。

附加信息:



我测试了 id_rsa_ac2 并给出了成功验证的消息。但奇怪的是给用户名与原来的帐户不与 ac2 帐户用户名



Hi {username!}您已成功通过身份验证,但GitHub不提供shell访问权限。 //这里用户标识应该来自ac2,但是它显示的是id_rsa的userid而不是id_rsa_ac2



信息:Final Code



@ VonC的答案有效,并且添加了最终代码作为我的答案,如果任何人想要使用的话。

为了将配置考虑在内,您需要在远程地址中使用主机名称:

  git remote add origin ac2.github.com:myaccount/my 

如果您定义了一个 HOME 环境变量(该变量在Windows上未默认定义,但是在使用msysgit git-cmd.bat )到一个您有.ssh目录的目录,它的 id_rsa_ac2 私钥和 id_rsa_ac2.pub 公共密钥,那么它就可以工作。


I am trying since more than 3 hours to setting up multiple account for github and litteraly tired. I have tried out almost all possible way describe here, github and articles and none of them worked. I am completely newbie to github and Unix as well. So need your help to fix this. Here below what I am doing

I am using Windows 7 and have set two ssh key for two different accounts.

  1. id_rsa
  2. id_rsa_ac2

Than created config file in .ssh directory of the User and added below code

#Account one
Host github.com
    HostName github.com
    PreferredAuthentications publickey
    IdentityFile /c/Projects/.ssh/id_rsa

#Account two
Host ac2.github.com
    HostName github.com
    PreferredAuthentications publickey
    IdentityFile /c/Projects/.ssh/id_rsa_ac2

Now I am trying to add remote by using below code

git remote add origin git@ac2.github.com:myaccount/my.git

and push with bellow code

git push origin master

But when I am trying to push it is giving me Error: Error: Permission to myaccount/my.git denied to {account}. // where it is considering default user account and not for ac2 user account fatal: Could not read from remote repository.

Please make sure you have the correct access rights and the repository exists.

Thanks a lot..

Additional Info:

I have test the id_rsa_ac2 and giving successfully authenticated message. But the strange thing is giving username with original account not with the ac2 account username

Hi {username!} You've successfully authenticated, but GitHub does not provide shell access. //here user id should be from ac2 but it is showing userid from id_rsa and not from id_rsa_ac2

INFORMATION: Final Code

@VonC's answer worked and adding final code as my answer if anyone want to use.

解决方案

For your config to be taken into account, you need to use its Host name in your remote address:

git remote add origin ac2.github.com:myaccount/my

If you have defined a HOME environment variable (which isn't defined by default on Windows, but is defined if you are using the msysgit git-cmd.bat) to a directory under which you have your .ssh directory, with its id_rsa_ac2 private key, and id_rsa_ac2.pub public key, then it will work.

这篇关于GitHub:多账号设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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