2017-07-04 30 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-)。

相关问题