2011-10-28 89 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 

以每個用戶身份登錄。他們應該指向不同的目錄。

相關問題