2012-04-06 26 views
6

我創建了一個deploy用戶,生成一個ssh_key,我將id_rsa.pub添加爲github部署密鑰。如何在github上爲1個用戶添加用於2個回購的部署密鑰

這個deploy用戶需要拉2回購,所以我添加相同的ssh_key到另一個回購部署密鑰。

但是github告訴我,部署密鑰已經在使用中。

我不知道如何爲1個用戶添加2個id_rsa.pub。

更新:

我添加id_rsa_assets額外的,但我還是不能拉。

ssh-add .ssh/id_rsa_assets 

無法打開與身份驗證代理的連接。

的.ssh/config中

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

Host assets 
    Hostname github.com 
    User git 
    IdentityFile ~/.ssh/id_rsa_assets 
+0

[github部署密鑰的可能重複:如何爲單個機器授權多個存儲庫](https://stackoverflow.com/questions/11656134/github-deploy-keys-how-do-i-authorize -more-one-repository-for-a-single-mac) – 2017-10-11 18:48:02

回答

8

您可以創建任何名稱的兩個公鑰/私鑰你想:

~/.ssh 
    repo1 
    repo1.pub 
    repo2 
    repo2.pub 

    config 

(即它沒有透露姓名id_rsa(.pub)工作,只要你指明ssh在哪裏尋找
這就是'config'發揮作用的地方:config文件包括GitHub repo1和GitHub的兩個連接的名稱repo2用,爲每個連接,路徑到您的私人回購鍵,如「change github account mac command line」和「Quick Tip: How to Work with GitHub and Multiple Accounts」描述:

Host githubRepo1 
HostName github.com 
User git 
IdentityFile ~/.ssh/repo1 

Host githubRepo2 
HostName github.com 
User git 
IdentityFile ~/.ssh/repo2 

這樣,你可以從任何兩個回購拉,只要你正在使用他們的ssh地址。

+0

當我運行ssh-add〜/ .ssh/repo2時它說'無法打開連接到您的身份驗證代理程序。 – 2012-04-06 11:54:29

+1

@guilin桂林:參見https://www.cs.indiana.edu/Facilities/FAQ/Security/openssh.html:然後你的會話不在'ssh-agent'下運行。您可以通過運行以下代碼重新啓動代理下的新shell: 'exec ssh-agent bash' 您可以在其中用您選擇的shell替換'bash'。一旦你這樣做了,你應該可以運行'ssh-add'來加載你的密鑰。 – VonC 2012-04-06 11:57:56

相關問題