2014-02-17 38 views
0

有一段時間了,我一直在Git bash(Mysysgit for Windows)中使用BitBucket。最近我添加了GitHub,但是當git存儲我的BitBucket證書時,它不適用於GitHub。GitHub不停地詢問用戶名/密碼; BitBucket不

我試過各種事情和方法(其中this tutorial和各種SO問題)。

下面是我詳細做了:

1)對GitHub上創建密鑰對。

2)將公鑰上傳到GitHub帳戶設置中的SSH keys

3)測試了密鑰對:

$ ssh -T [email protected] 
Enter passphrase for key '/c/Users/***/.ssh/id_rsa_github': 
Hi ***! You've successfully authenticated, but GitHub does not provide shell access. 

$ ssh -T [email protected] 
logged in as ***. 
You can use git or hg to connect to Bitbucket. Shell access is disabled. 

4)更新我的配置文件有以下幾點:

Host bitbucket.* 
User *** 
IdentityFile ~/.ssh/id_rsa 

Host github.* 
HostName github.com 
User *** 
ForwardAgent yes 
IdentityFile ~/.ssh/id_rsa_github 

5)新增的私鑰和密碼:

$ eval `ssh-agent` 
$ ssh-add ~/.ssh/id_rsa_github 
Enter passphrase for /c/Users/***/.ssh/id_rsa_github: 
Identity added: /c/Users/***/.ssh/id_rsa_github (/c/Users/***/.ssh/id_rsa_github) 
$ ssh-add -L 
ssh-rsa **key here*** /c/Users/***/.ssh/id_rsa_github 

6)增加了.bashrc文件自動啓動的的ssh-agent:

eval `ssh-agent` 

而且還是:

$ git push origin master 
Username for 'https://github.com': 

我要去哪裏錯了?


編輯:以下建議切換到SSH後,混帳不問我的密碼/用戶名每次。但是,現在它每次都要求我的密碼。從一個混帳會話:

$ git push origin master 
Enter passphrase for key '/c/Users/***/.ssh/id_rsa_github': 
Counting objects: 5, done. 
*** 

$ git commit -am "Minor edit" 
1 file changed, 1 insertion(+), 1 deletion(-) 

$ git push origin master 
Enter passphrase for key '/c/Users/***/.ssh/id_rsa_github': 

我已經更新了我.bashrc文件Github上suggests it,但據我瞭解,它應該只爲我的密碼再多問。即使我以管理員權限運行mysysgit,密碼也不會保存。

+1

您正在使用https回購網址,即,你根本沒有使用ssh。 – AD7six

+0

謝謝@ AD7six,切換到SSH後,它不再向我要求我的用戶名/密碼。然而,現在它每次都會詢問我的密碼(在用'ssh-add'添加Github密鑰後,甚至在手動啓動ssh-agent之後)。 – Jura25

回答

0

我做固定的問題如下:使用GitHub的建議爲.bashrc

1)發現here(感謝@poke);

2)改變了.bashrc代碼的位置添加到我的鑰匙:

... 
if ! agent_is_running; then 
    agent_start 
    ssh-add ~/.ssh/id_rsa 
    ssh-add ~/.ssh/id_rsa_github 
elif ! agent_has_keys; then 
    ssh-add ~/.ssh/id_rsa 
    ssh-add ~/.ssh/id_rsa_github 
fi 
... 

3)更新我的config文件依據,以到位桶的文檔here到:

# Bitbucket account 
Host bitbucket.org 
HostName bitbucket.org 
PreferredAuthentications publickey 
IdentityFile ~/.ssh/id_rsa 

# GitHub account 
Host github.com 
HostName github.com 
PreferredAuthentications publickey 
IdentityFile ~/.ssh/id_rsa_github 

4),並此步驟從我以前的嘗試中丟失,請使用bash命令ps列出所有進程,然後kill任意實例ssh-agent(這樣就沒有ssh-agent了)。

5)然後我重新啓動git bash,並在啓動時立即提示輸入Github密碼。然而,這一次,ssh-agent記住了它。

此前我也驗證過沒有多個實例ssh-agent,但我並沒有殺死每一個ssh-agent實例,因爲這是違反直覺的。但是,爲了使.bashrc文件正常工作,這顯然是需要的。

希望這些步驟也可能對其他類似問題有幫助。

3

GitHub提供了多種訪問存儲庫的方式。目前的默認值是通過https不使用您的SSH信息的URL。這些URL看起來像這樣:

https://github.com/<owner>/<project>.git 
[email protected]:<owner>/<project>.git 

只需切換到第二種,SSH地址和Git將使用您的SSH信息。

+0

感謝您的回答和解釋:它不再要求我的密碼和用戶名。但是,現在它一直在詢問我的密碼(我更新了我的問題)。你有沒有想法? – Jura25

+1

請參閱[本指南](https://help.github.com/articles/working-with-ssh-key-passphrases#platform-windows)瞭解如何正確設置ssh-agent。 – poke