2017-07-04 31 views
-1

在開始之前,我應該說我已經閱讀了很多關於這個問題的主題(列在本文結尾處),但沒有一個爲我工作,或者我在這裏錯過了一些微不足道的東西。如何通過SSH爲兩個不同的存儲庫設置兩個不同的Github帳戶?

起初,我使用HTTPS克隆了存儲庫,但隨後我從here的文檔切換到SSH。我確實生成了每個SSH密鑰,並將其添加到ssh-agent之後的文檔從here

在幾行(使用假數據,~意味着我的主目錄),這是我做了什麼:

$ ssh-keygen -t rsa -b 4096 -C "[email protected]" 
Enter a file in which to save the key (~/.ssh/id_rsa): [Press enter] 
Enter passphrase (empty for no passphrase): [Type a passphrase] 
Enter same passphrase again: [Type passphrase again] 

$ ssh-keygen -t rsa -b 4096 -C "[email protected]" 
Enter a file in which to save the key (~/.ssh/id_rsa_second): [Press enter] 
Enter passphrase (empty for no passphrase): [Type a passphrase] 
Enter same passphrase again: [Type passphrase again] 

$ eval "$(ssh-agent -s)" 
Agent pid 12697 

$ ssh-add ~/.ssh/id_rsa 
Identity added: ~/.ssh/id_rsa (~/.ssh/id_rsa) 

$ ssh-add ~/.ssh/id_rsa_second 
Identity added: ~/.ssh/id_rsa_second (~/.ssh/id_rsa_second) 

$ ssh-add -l 
4096 SHA256:gb+Gn4SqiyAP5ABUsmX6Xz11RHTSvDsWgEE5P2R2VTE ~/.ssh/id_rsa (RSA) 
4096 SHA256:yxWMompayDNtYjv5y+FfJl7OpQ5Qu90kPgdXXvx6DRA ~/.ssh/id_rsa_second (RSA) 

下一個步驟是創建~/.ssh/config文件,內容如下:

#first account 
Host github.com-first 
    HostName github.com 
    User git 
    IdentityFile ~/.ssh/id_rsa 

#second account 
Host github.com-second 
    HostName github.com 
    User git 
    IdentityFile ~/.ssh/id_rsa_second 

我在這裏停下來試試,通過將id_rsa_second的SSH發佈密鑰添加到我想要使用它的存儲庫(這不需要解釋)。下一頁git pull

$ git pull 
Bad owner or permissions on /home/rperez/.ssh/config 
fatal: Could not read from remote repository. 

Please make sure you have the correct access rights 
and the repository exists. 

然後我嘗試了以下內容:

  • 更改.git/config文件到以下幾點:

    [remote "origin"] 
        url = [email protected]:repo/repo.git 
        fetch = +refs/heads/*:refs/remotes/origin/* 
    

但它並沒有通過這項工作,我的意思是我得到和以前完全一樣的錯誤。

我做錯了什麼?我錯過了什麼?

我已閱讀:

Note: The title may seem confusing but it is correct because it is what I want to achieve I am just talking about one example but at the end I should be able to setup more than one account pointing to different repositories.

+0

可能重複多個bitbucket帳戶的ssh配置 - 簡單的例子,但'遠端掛起意外'](https://stackoverflow.com/questions/14409761/ssh-config-for-multiple-bitbucket-帳戶 - 簡單例子 - 丁得到-遠程) – Ikke

回答

1

它不工作的原因是因爲這個錯誤的:

Bad owner or permissions on /home/rperez/.ssh/config

SSH是挑剔的(出於安全原因)有關的敏感文件的權限。

man ssh說:

~/.ssh/config 
     This is the per-user configuration file. The file format and configuration 
     options are described in ssh_config(5). Because of the potential for abuse, 
     this file must have strict permissions: read/write for the user, and not 
     writable by others. 

因此,檢查的/home/rperez/.ssh/config文件的權限。他們應該是0644(-rw-r--r-)。

相關問題