2015-10-05 45 views
1

我有兩個github帳戶,我正在嘗試配置github,我的環境和ssh密鑰,以便我能夠推送到任何回購站點,無論它位於我的github.com/user1或github.com/user2帳戶。我花了好幾個小時試圖根據我所能找到的所有資源努力做到這一點,唉,我似乎缺乏瞭解這個問題的理解。任何人都可以幫助我正確配置這個配置嗎?Git錯誤:權限user1/repoA.git被拒絕給user2

我在github.com上的兩個帳戶中的每一個都設置了不同的電子郵件地址; github.com/user1 = '[email protected]github.com/user2 = [email protected]

我有兩個生成的SSH密鑰第一個在.ssh/id_rsa & .ssh/id_rsa.pub並且此SSH密鑰保存在github.com/user1。第二個SSH密鑰.ssh/user2 .ssh/user2_rsa and saved in github.com/user1`。

我有一個.ssh/config file其中包含:

Host user1.github.com 
HostName github.com 
IdentityFile ~/.ssh/user1 
Host user2.github.com 
HostName github.com 
IdentityFile ~/.ssh/id_rsa 

當我運行ssh-add -l我看到這兩個鍵 '加載'。

當我運行ssh -T [email protected]我得到Hi user2! You've successfully authenticated, but GitHub does not provide shell access.

當我運行ssh -T [email protected]我得到Hi user2! You've successfully authenticated, but GitHub does not provide shell access.

我可以成功地推到一個回購在「github.com/user2」。

我無法推送到'github.com/user1'中的回購,出現以下錯誤消息;

ERROR: Permission to user1/repo.git denied to user2. 
fatal: Could not read from remote repository. 

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

我'的.gitconfig」文件包含:

[user] 
    name = my full name 
    email = [email protected] 
[GitHub] 
    user = user1 

從我所看到的,似乎我的局部環境,CMD,我已經堅持爲用戶2,並且不允許用戶2提交到user1 github帳戶。但是a)我認爲.ssh/config中的腳本應該認識到,當我推送到user1時,它應該使用user1 ssh,反之亦然,但這似乎沒有發生,並且b)我的.gitcofig將我的user.email和我的GitHub用戶視爲user1在運行ssh -T ...後與我的身份驗證爲user2衝突。

我已經嘗試了很多東西,我的內褲現在正處於適當的扭曲狀態。任何人都可以讓我正確設置這個,或者指導我如何清除所有SSh,並重新開始並正確設置(注意,我還設置了需要配置的Heroku帳戶)。

在此先感謝。

回答

1

The 2nd SSH key in .ssh/user2 .ssh/user2_rsa

然而,你.ssh/config使用id_rsauser2.github.com

Host user2.github.com 
    HostName github.com 
    IdentityFile ~/.ssh/id_rsa 
         ^^^^^^ 

而且user1.pub公鑰似乎對user2帳戶註冊,因爲ssh -T [email protected]返回Hi user2!

檢查您的本地配置,以及還請在github上檢查哪個公共密鑰已添加到哪個帳戶。

+0

謝謝VonC,感謝。我在一個正確的混亂,所以我只是決定刪除所有的鑰匙,並重新開始,現在一切工作正常。我將刪除這個Q,因爲我不確定這對其他人是否有建設性。 – jbk

+0

@jbk不,你可以留下問題,因爲它說明了ssh/config的工作原理。 – VonC

+0

我有同樣的問題,但在Windows上。建議如何處理它將不勝感激 –