2015-07-20 125 views
1

我使用GitHub在文件上存在SSH密鑰。我正在嘗試將更改推送給其他人的GitHub項目。我有協作者訪問該帳戶。在推送GitHub期間從命令行使用SSH密鑰?

我被提示輸入密碼:

$ git push 
warning: push.default is unset; its implicit value is changing in 
Git 2.0 from 'matching' to 'simple'. To squelch this message 
and maintain the current behavior after the default changes, use: 

    git config --global push.default matching 

To squelch this message and adopt the new behavior now, use: 

    git config --global push.default simple 

When push.default is set to 'matching', git will push local branches 
to the remote branches that already exist with the same name. 

In Git 2.0, Git will default to the more conservative 'simple' 
behavior, which only pushes the current branch to the corresponding 
remote branch that 'git pull' uses to update the current branch. 

See 'git help config' and search for 'push.default' for further information. 
(the 'simple' mode was introduced in Git 1.7.11. Use the similar mode 
'current' instead of 'simple' if you sometimes use older versions of Git) 

Username for 'https://github.com': xxxxxx 
Password for 'https://[email protected]': 
remote: Invalid username or password. 
fatal: Authentication failed for 'https://github.com/weidai11/cryptopp.git/' 

GitHub的在Which remote URL should I use?幫助只討論一個桌面客戶端的情況下SSH。我想他們有一個他們希望我使用的應用程序,但我並不想使用它。

如何讓命令行工具使用我的SSH密鑰將更改推送到GitHub帳戶?


這與How do I checkout a GitHub project from command line as a Collaborator?。我永遠無法使用憑據作爲協作者簽出,現在我陷入了這個密碼驗證陷阱。

回答

1

要推送另一個帳戶,您需要存儲在您的~/.ssh文件夾中的其他帳戶的私人/公共ssh密鑰。

您還需要一個ssh配置文件(~/.ssh/config)類似:

的ssh配置文件中聲明多個密鑰:

Host githubUserA 
    Hostname github.com 
    IdentityFile ~/.ssh/id_rsa 
    User git 

Host githubUseB 
    Hostname github.com 
    IdentityFile ~/.ssh/other 
    User git 

你就可以使用SSH URL像

githubUserA:userA/myrepo1 
githubUserB:userB/myrepo2 

第二個賬戶可以通過添加一個新的遠程從同一個回購使用:

git remote add guserB githubUserB:userB/myrepo2 
git push gUserB myBranch 
+0

謝謝VonC。有沒有辦法將GitHub配置爲***只使用SSH密鑰來訪問我的密碼?如果GitHub配置正確,那麼它不會浪費我的時間與密碼提示,我不會做這個客戶端(在多臺機器上)? – jww

+1

@jww您將配置的是與您本地回購相關的遠程URL:鍵入'git remote -v'來檢查那些只是ssh url。並且/或者您可以使用'insteadOf'指令,如http://stackoverflow.com/a/26814985/6309中所述。 – VonC