2017-07-17 141 views
1

我在远程访问的机器上使用git(github)时遇到了一些问题。我通过ssh从家里登录到我的工作计算机上。通过远程机器连接到github的ssh密钥问题

[email protected]$ ssh [email protected] 

之后,我尝试通过家庭对工作计算机上的github执行pull或push请求,例如,

[email protected]$ git pull origin branch 

后,我收到错误:

Permission denied (publickey). 
fatal: Could not read from remote repository. 

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

我试图从我的工作电脑加载SSH密钥使用:

[email protected]$ eval "$(ssh-agent -s)" 
[email protected]$ ssh-add ~/.ssh/id_rsa 

但仍没有运气。当我在工作计算机上工作时,我可以向github发出请求而不出现任何问题;所以它似乎与我的ssh会话的ssh密钥的状态有关的问题。

感谢您的帮助!

+0

验证您在workViaHome上添加的私钥实际上是您在github上添加的公钥的正确密钥。还要验证〜/ .ssh目录的访问权限是否正确。最后,尝试使用与git相同的用户/端口对github执行ssh操作,并添加详细标志以获取更多信息。 – DusteD

+0

所以我孤立了这个问题,以ssh-add不触发git使用〜/ .ssh/id_rsa键,它仍然尝试使用默认键。我现在被骗了,因为我在github上添加了默认密钥并且它可以工作。我用ssh -vT [email protected]弄明白了。我仍然不确定为什么ssh继续回落到默认密钥 – BenJ

回答

0

如果未在配置中另行指定,或者ssh-agent未提供任何其他密钥,SSH将使用默认密钥。

如果您在非标准位置使用的密钥已添加到gnome-keyring中,您可能会注意到此行为,因为gnome-keying仅针对图形会话启动,而不是针对ssh会话启动。

当然,您可以通过在工作计算机上的~/.ssh/config中正确配置此密钥来解决此问题。只需添加

Host github.com 
    IdentityFile ~/.ssh/path_to_key 
    IdentitiesOnly yes