【问题标题】:ssh key issue connecting to github via remote machine通过远程机器连接到 github 的 ssh 密钥问题
【发布时间】:2017-07-17 18:41:35
【问题描述】:

我在远程访问的机器上使用 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-keys 的状态似乎存在问题。

感谢您的帮助!

【问题讨论】:

  • 验证你在workViaHome上添加的私钥实际上是你在github上添加的公钥的正确私钥。还要验证 ~/.ssh 目录的访问权限是否正确。最后,尝试使用与 git 相同的用户/端口 ssh 到 github,并添加详细标志以获取更多信息。
  • 所以我将问题隔离到 ssh-add 没有触发 git 使用 ~/.ssh/id_rsa 密钥,它仍在尝试使用默认密钥。我现在作弊了,因为我将默认密钥添加到 github 并且它可以工作。我使用 ssh -vT git@github.com 来解决这个问题。我仍然不确定为什么 ssh 一直回退到默认密钥

标签: git github ssh


【解决方案1】:

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

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-07-11
    • 2021-12-17
    • 2017-04-17
    • 2011-07-24
    • 1970-01-01
    • 2014-10-28
    • 1970-01-01
    相关资源
    最近更新 更多