[英]git public key for more repositories
我有以下問題。
我有2個項目,我使用github。 第一個項目進展順利,我創建了一個公鑰,輸入密碼並推入github。 沒問題。
第二個項目,我創建了另一個公鑰,當我想推送到第二個存儲庫時,它一直要求第一個代碼/.ssh/id_rsa的密碼。 但是id_rsa擁有我第一個項目的公鑰。 所以當然,當我輸入密碼短語時它不會起作用,因為它會嘗試進入第一個回購而不是第二個回購。
我怎樣才能創建一個公鑰並告訴git我想推送到另一個回購?
謝謝。
您需要在~/.ssh/config
文件中聲明不同的ssh密鑰,正如我在“ 如何管理〜/ .ssh目錄中的多個ssh密鑰”中所述。
我建議不要使用鍵的默認名稱,而是:
~/.ssh/proj1
~/.ssh/proj1.pub
~/.ssh/proj2
~/.ssh/proj2.pub
然后有一個~/.ssh/config
像:
Host ghproj1
User git
Hostname github.com
IdentityFile ~/.ssh/proj1
IdentitiesOnly yes
Host ghproj2
User git
Hostname github.com
IdentityFile ~/.ssh/proj2
IdentitiesOnly yes
您需要在兩個repos中更改原始URL:
cd /path/to/cloned/proj1
git remote set-url origin ghproj1:yourProject1
cd /path/to/cloned/proj2
git remote set-url origin ghproj1:yourProject2
更多信息請訪問:
像ghproj1:yourProject1
這樣的url ghproj1:yourProject1
是一個ssh,它將顯式使用你在~/.ssh/config
為ghproj1
條目指定的密鑰。
在OP的情況下( 下面的答案 ),正確的URL將是:
~/.ssh/id_recaprojekt
注意: 您需要指定私鑰的路徑(私有,不是公共,不是.pub
)
cd /path/to/cloned/plastickychirurg
git remote set-url origin plastickychirurg:michalfeher/plastickychirurg.git
cd /path/to/cloned/recaprojekt
git remote set-url origin recaprojekt:michalfeher/recaprojekt.git
請注意,我在主機條目中添加了“主機名”。
〜/ .ssh / config文件中這些條目的所有想法是不(重復不 )將git
或github.com
放在url中(它由與每個條目相關聯的項目完成):
所以:
git@github.com:michalfeher/recaprojekt.git
是相同的:
recaprojekt:michalfeher/recaprojekt.git
除了第二個url將使用ssh密鑰
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.