Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过远程计算机连接到github的ssh密钥问题_Git_Github_Ssh - Fatal编程技术网

通过远程计算机连接到github的ssh密钥问题

通过远程计算机连接到github的ssh密钥问题,git,github,ssh,Git,Github,Ssh,我在远程访问的机器上使用git(github)时遇到一些问题。我从家里通过ssh登录到我的工作计算机,例如 me@home$ ssh me@work 之后,我尝试通过家用电脑向我的工作电脑上的github发出拉或推请求,例如 me@workViaHome$ git pull origin branch 之后,我收到错误: Permission denied (publickey). fatal: Could not read from remote repository. Please m

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

me@home$ ssh me@work
之后,我尝试通过家用电脑向我的工作电脑上的github发出拉或推请求,例如

me@workViaHome$ 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密钥:

me@workViaHome$ eval "$(ssh-agent -s)"
me@workViaHome$ ssh-add ~/.ssh/id_rsa
但还是没有运气。当我在我的工作计算机上时,我可以向github发出请求,而不会出现任何问题;因此,由于ssh会话,ssh密钥的状态似乎存在问题


谢谢你的帮助

如果在配置中没有另外指定默认密钥,或者如果
SSH代理未提供任何其他密钥,则SSH将使用默认密钥

如果您在非标准位置使用密钥,您已经在
gnome钥匙圈中添加了该密钥,您可能会注意到这种行为,因为
gnome钥匙圈
仅针对图形会话启动,而不针对
ssh
会话启动

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

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

验证您在workViaHome上添加的私钥是否与您在github上添加的公钥对应。还要验证~/.ssh目录的访问权限是否正确。最后,尝试使用与git相同的用户/端口ssh到github,并添加详细标志以获取更多信息。因此,我将问题隔离到ssh add,而不是触发git使用~/.ssh/id\u rsa密钥,它仍在尝试使用默认密钥。我现在作弊了,因为我将默认密钥添加到github,并且它可以工作。我使用了ssh-vTgit@github.com去弄清楚。我仍然不知道为什么ssh总是回到默认密钥