2011-10-28 58 views
7

这可能不是一个重复;我已经通读了StackOverflow上的许多类似问题,但没有解决这个问题。Github多帐户一台电脑总是看到一个帐户

我想在Ubuntu Linux上使用多个git帐户,每当我尝试从第二个帐户推送它认为我仍然使用第一个帐户的用户名。

$ git push -u origin master 
ERROR: Permission to <act2>/<repo>.git denied to <act1>. 

我第一次尝试了多SSH密钥方法。当我收到上述错误时,我在本地机器上创建了一个全新的用户,以该用户身份登录,重新创建本地回购(首次推送)并重试。同样的错误。我的本地.config显示用户,以及我的〜/ .gitconfig。

任何想法?

我做的: SSH @localhost 然后SSH -vvv -T [email protected]

我得到这个有趣的输出。它似乎脱落并在我的帐户中找到钥匙。但不知何故,它在我的帐户中使用了一个密钥,这实际上是不应该访问的。


debug1: Host 'github.com' is known and matches the RSA host key. 
debug1: Found key in /home//.ssh/known_hosts:1 
debug2: bits set: 513/1024 
debug1: ssh_rsa_verify: signature correct 
debug2: kex_derive_keys 
debug2: set_newkeys: mode 1 
debug1: SSH2_MSG_NEWKEYS sent 
debug1: expecting SSH2_MSG_NEWKEYS 
debug3: Wrote 16 bytes for a total of 1015 
debug2: set_newkeys: mode 0 
debug1: SSH2_MSG_NEWKEYS received 
debug1: SSH2_MSG_SERVICE_REQUEST sent 
debug3: Wrote 48 bytes for a total of 1063 
debug2: service_accept: ssh-userauth 
debug1: SSH2_MSG_SERVICE_ACCEPT received 
debug2: key: 
debug2: key: 
debug2: key: /home//.ssh/identity ((nil)) 
debug2: key: /home//.ssh/id_rsa() 
debug2: key: /home//.ssh/id_dsa ((nil)) 
debug3: Wrote 64 bytes for a total of 1127 
debug1: Authentications that can continue: publickey 
debug3: start over, passed a different list publickey 
debug3: preferred gssapi-keyex,gssapi-with-mic,gssapi,publickey,keyboard-interactive,password 
debug3: authmethod_lookup publickey 
debug3: remaining preferred: keyboard-interactive,password 
debug3: authmethod_is_enabled publickey 
debug1: Next authentication method: publickey 
debug1: Offering public key: 
debug3: send_pubkey_test 
debug2: we sent a publickey packet, wait for reply 
debug3: Wrote 368 bytes for a total of 1495 
debug1: Authentications that can continue: publickey 
debug1: Offering public key: 
debug3: send_pubkey_test 
debug2: we sent a publickey packet, wait for reply 
debug3: Wrote 368 bytes for a total of 1863 
debug1: Remote: Forced command: gerve 
debug1: Remote: Port forwarding disabled. 
debug1: Remote: X11 forwarding disabled. 
debug1: Remote: Agent forwarding disabled. 
debug1: Remote: Pty allocation disabled. 
debug1: Server accepts key: pkalg ssh-rsa blen 277 
debug2: input_userauth_pk_ok: fp 
debug3: sign_and_send_pubkey 
debug3: Wrote 640 bytes for a total of 2503 
debug1: Remote: Forced command: gerve 
debug1: Remote: Port forwarding disabled. 
debug1: Remote: X11 forwarding disabled. 
debug1: Remote: Agent forwarding disabled. 
debug1: Remote: Pty allocation disabled. 
debug1: Authentication succeeded (publickey). 
debug1: channel 0: new [client-session] 
debug3: ssh_session2_open: channel_new: 0 
debug2: channel 0: send open 
debug1: Requesting [email protected] 
debug1: Entering interactive session. 
debug3: Wrote 128 bytes for a total of 2631 
debug2: callback start 
... 
+0

在一个虚拟机(其中act1不存在)中再次完成了整个事情,它的工作......但这绝对不是理想的:-( – AndrewStone

回答

9

发生这种情况是因为ssh-agent缓存ssh密钥(甚至可以删除该文件,并且仍然允许ssh成功连接,直到缓存被清除),并且会优先考虑缓存的密钥,甚至优先于通过IdentityFile指定的密钥。你可以看到哪些文件被运行缓存:

ssh-add -l 

您可以强制的ssh-agent:在对每个连接的.ssh/config中包括IdentitiesOnly“是”忽略缓存:

Host github 
    HostName github.com 
    User git 
    IdentityFile ~/.ssh/id_rsa 
    IdentitiesOnly yes 

Host github-work 
    HostName github.com 
    User git 
    IdentityFile ~/.ssh/id_dsa_work 
    IdentitiesOnly yes 

更多的信息在这里:http://sealedabstract.com/code/github-ssh-with-multiple-identities-the-slightly-more-definitive-guide/

我花了很长时间才发现这一点,希望它有助于某人。

+0

这是一个巨大的帮助菲尔。这立即解决了我的问题。 – AKWF

0

查看.git文件夹的权限及其内容。使用ssh github.com -vvvv确认将哪个SSH密钥传递给github。

+0

ssh [email protected] -vvvv说“嗨”(错帐户)我会挖掘通过所有的输出,看看为什么 – AndrewStone

+0

由于某种原因ssh到达我的其他用户行为并看着它输出:debug2:key:/ home/ /.ssh/id_rsa和“远程:强制命令:gerve “ – AndrewStone

+0

你可能有错误的主目录,'pwd〜'说了什么? –

3

为了说明我对这个答案的假设,它从问题标题中听起来好像你真正想要做的就是推动GitHub被识别为不同的GitHub用户。

如果是这样的话,您不应该在系统上创建多个用户,只是为了通过SSH推送不同的GitHub用户。正确的做法是在~/.ssh/config中设置github.com的两个别名,这两个别名指定不同的标识文件as described here。例如,你可能在你的~/.ssh/config如下:

Host github-act1 
    HostName github.com 
    User git 
    IdentityFile /home/whoever/.ssh/id_rsa.act1 

Host github-act2 
    HostName github.com 
    User git 
    IdentityFile /home/whoever/.ssh/id_dsa.act2 

然后,您可以添加两个遥控器来你的资料库:

git add remote act1 [email protected]:whoever/whatever.git 
git add remote act2 [email protected]:whoever/whatever.git 

然后如果你想推,你可以做一个用户:

git push act1 master 

...或者作为第二个帐户:

git push act2 master 
+0

是的,我先尝试了这个方法,同样的错误,于是我去了多个unix帐户方法,有一些SSH配置问题... – AndrewStone

+0

@ArewrewStone:你如何登录作为第二个用户?echo $ HOME是什么显示你一次y您是否以第二位用户身份登录? –

+0

ssh @localhost。它显示/ home/。对不起,延迟响应4天停电 – AndrewStone

0
debug2: key: 
debug2: key: 
debug2: key: /home//.ssh/identity ((nil)) 
debug2: key: /home//.ssh/id_rsa() 
debug2: key: /home//.ssh/id_dsa ((nil)) 

这看起来非常可疑。为什么你的主目录只是/home/?如果多个用户拥有相同的主目录,那么我并不感到惊讶,ssh为两个用户找到了相同的密钥。检查结果

echo $HOME 

以每个用户身份登录。他们应该指向不同的目录。

相关问题