【问题标题】:GitHub: Permission denied (publickey). Unable to push to serverGitHub:权限被拒绝(公钥)。无法推送到服务器
【发布时间】:2017-12-18 03:30:38
【问题描述】:

我收到错误:

VehicleXray git:(master) ✗ git push live master
Permission denied (publickey).
fatal: Could not read from remote repository.

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

命令“git remote -v”显示:

live    ssh://root@vehiclexray.com/var/repo/VehicleXray.git (fetch)
live    ssh://root@vehiclexray.com/var/repo/VehicleXray.git (push)
origin  https://github.com/enayet123/VehicleXray.git (fetch)
origin  https://github.com/enayet123/VehicleXray.git (push)

我显然是 GitHub 的新手,对如何使用它了解甚少。我已经尝试使用本地存储在我的笔记本电脑上的私钥和提供给我的服务器和 GitHub 的公钥创建一个 SSH 密钥。我做错了什么?

【问题讨论】:

    标签: git github


    【解决方案1】:

    这对我有用:

    第 1 步 - git remote rm origin
    第 2 步 - select the http option in github
    第 3 步 - 再次运行以下命令

    git remote add origin https://github.com/yourdirectory/link.git  
    git branch -M main  
    git push -u origin main  
    

    【讨论】:

      【解决方案2】:

      您的服务器上的公钥似乎有问题。尝试使用 ssh 登录:

      ssh -vvv root@vehiclexray.com
      

      -vvv 选项打印调试消息

      您的公钥应该在~/.ssh/authorized_keys 文件中。还必须在sshd_config 文件中启用公钥身份验证:PubkeyAuthentication yes。更改此文件后,您必须重新启动 ssh。

      同时选择root 作为用户可能不是最好的主意。可以在 sshd 级别禁用以 root 身份登录。您应该创建非特权用户来访问 git 存储库。

      另一件事:只能推送到裸存储库。您可以使用git clone --bare <repository> 命令克隆裸存储库。

      更多信息:Git on the Server - Setting Up the Server

      【讨论】:

      • 认证成功
      【解决方案3】:

      您的问题与 Github 无关。您在推送到 ssh://root@vehiclexray.com/ 时遇到 ssh 问题。解决方法和 GH 一样:把你的公钥复制到root@vehiclexray.com:

      ssh-copy-id root@vehiclexray.com
      

      【讨论】:

      • 是的!我爱你。我不知道为什么,但是当我手动复制 SSH 密钥时它不起作用?
      【解决方案4】:

      查看 git hubs 帮助https://help.github.com/articles/pushing-to-a-remote#what-can-i-push-to

      试试这个

      1. git 远程 rm 来源
      2. git 远程添加来源
      3. git@github.com:user/repo.git git push origin master

      【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-02-01
      • 2012-01-18
      • 2012-04-25
      • 2014-12-03
      • 1970-01-01
      • 2011-12-24
      相关资源
      最近更新 更多