GitHub:权限被拒绝(publickey)。无法推送到服务器

时间:2017-07-13 11:19:48

标签: git github

我收到错误:

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的新手,对如何使用它的理解很少。我已经尝试创建一个SSH密钥,其中私钥存储在我的笔记本电脑上,并且公钥给我的服务器和GitHub。我做错了什么?

4 个答案:

答案 0 :(得分:1)

看起来您的服务器上的公钥可能有问题。尝试使用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

答案 1 :(得分:1)

你的问题与Github没什么关系。你有{s}麻烦推进ssh://root@vehiclexray.com/。解决方案与GH相同:将您的公钥复制到root@vehiclexray.com

ssh-copy-id root@vehiclexray.com

答案 2 :(得分:0)

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

试试这个

  1. git remote rm origin
  2. git remote add origin
  3. git@github.com:user / repo.git git push origin master

答案 3 :(得分:0)

这对我有用:

第 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  
相关问题