2016-03-25 107 views
1

我從github上兩個不同的私有倉庫工作的工作,我已經產生了爲他們每個人的兩把鑰匙和我有如下一個配置文件時管理SSH密鑰:如何與github上

Host github.com-frontend 
HostName github.com 
User lulzimfazlija2 
IdentitiesOnly yes 
IdentityFile ~/.ssh/id_rsa_frontend 

Host github.com-backend 
HostName github.com 
User lulzimfazlija2 
IdentitiesOnly yes 
IdentityFile ~/.ssh/id_rsa_backend 

的事情是當我嘗試從任何項目推送它仍然要求我從id_rsa而不是id_rsa_frontend或id_rsa_backend寫入密碼。

我該如何告訴git總是通過一個單一的鍵來識別。

我也想這樣:

$ ssh -T [email protected] 

關鍵輸入密碼 '/c/Users/lulzim/.ssh/id_rsa_frontend': 嗨lulzimfazlija2 /風險投資前端!您已成功通過身份驗證,但GitHub不提供shell訪問權限。

但是,當我做混帳推它仍然要求我從id_rsa鍵寫密碼。

有沒有什麼辦法可以讓我從每個項目的特定鍵總是問我。

+0

什麼是您試圖推入的URL?給我們輸出'git remote -v' –

+0

另外,這是什麼問題?你需要每次輸入密碼嗎? –

+0

其:[email protected]:lulzimfazlija2/venture-backend.git –

回答

0

ssh -T [email protected]是有效的,並將根據您的~/.ssh/config推送到github.com。

但是:

  • 請確保您的~/.ssh/config包括User git,不User lulzimfazlija2:你總是推到GitHub上(在SSH)爲git,而不是xxx:GitHub的將SSH密鑰驗證您的身份(that is associated to your GitHub account)。
    您的有效測試(ssh -T [email protected])實際上包含用戶git(這是正確的)。
    如果User git包括在~/.ssh/config,你的測試實際上是:
    ssh -T github.com-frontend

  • 關鍵輸入密碼意味着你的SSH私鑰是密碼保護。
    如果您想避免每次使用時輸入密碼,您需要add that ssh key to your ssh agent
    在一個git bash下

    eval $(ssh-agent -s) 
    ssh-add ~/.ssh/id_rsa_frontend 
    

然後你可以使用源URL,例如:

github.com-frontend:lulzimfazlija2/my_frontend_project 
github.com-backend:lulzimfazlija2/my_backend_project 

(不需要一個 '[email protected]' 前綴,如User git將在聲明~/.ssh/config