GitHub:多帐户设置

Cod*_*ver 7 github

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

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

  1. id_rsa
  2. id_rsa_ac2

比在.sshUser的目录中创建配置文件并添加到代码下面

#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
Run Code Online (Sandbox Code Playgroud)

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

git remote add origin git@ac2.github.com:myaccount/my.git
Run Code Online (Sandbox Code Playgroud)

并用波纹管代码推送

git push origin master
Run Code Online (Sandbox Code Playgroud)

但是,当我试图推动它给我错误: 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.

非常感谢..

附加信息:

我已经测试id_rsa_ac2并提供成功验证的消息.但奇怪的是,使用原始帐户的ac2用户名不是帐户用户名

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

信息:最终守则

如果有人想要使用,@ VonC的答案有效并添加最终代码作为我的答案.

Von*_*onC 3

为了考虑您的配置,您需要Host在远程地址中使用其名称:

git remote add origin ac2.github.com:myaccount/my
Run Code Online (Sandbox Code Playgroud)

如果您已将HOME环境变量(在 Windows 上默认情况下未定义,但在使用 msysgit 时已定义git-cmd.bat定义到您的 .ssh 目录及其id_rsa_ac2私钥和id_rsa_ac2.pub公钥的目录,则它会起作用的。