git GitHub:权限被拒绝(公钥)。致命:无法从远程存储库读取

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38556096/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 04:24:14  来源:igfitidea点击:

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

gitgithubgit-remote

提问by Ulli H

I′m having trouble with GitHub. I′ve playing around with a remote repository of Git.

我在使用 GitHub 时遇到问题。我一直在玩 Git 的远程存储库。

When I now try to make any changes to the remote directory, i.e.

当我现在尝试对远程目录进行任何更改时,即

git remote show origin

or

或者

git push -u origin master

I get this error

我收到这个错误

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

Please make sure you have the correct access rights and the repository exists. Ulrichs-MacBook-Pro:coredatatest ulrichheinelt$ git push -u origin master Permission denied (publickey). fatal: Could not read from remote repository.

权限被拒绝(公钥)。致命:无法从远程存储库读取。

请确保您拥有正确的访问权限并且存储库存在。Ulrichs-MacBook-Pro:coredatatest ulrichheinelt$ git push -u origin master 权限被拒绝(公钥)。致命:无法从远程存储库读取。

I would be happy, when I could start again with a new (empty) remote directory. Or is there a way, to fix this error?

当我可以使用新的(空的)远程目录重新开始时,我会很高兴。或者有没有办法解决这个错误?

This are my first steps with GitHub, started yesterday... Many thanks in advance!

这是我使用 GitHub 的第一步,从昨天开始……在此先感谢!

Edit 1

编辑 1

mysettings at https://github.com/UlliH/CoreDataTest/settings

https://github.com/UlliH/CoreDataTest/settings 上的设置

...

...

Edit 2

编辑 2

too early happy:-(

太早高兴了:-(

After setting the SSH and GPG keys, the errors are still the same. :-/

设置了SSH和GPG密钥后,错误还是一样。:-/

Edit 3

编辑 3

I think that's right so, but still the same...

我认为是这样,但还是一样......

enter image description here

在此处输入图片说明

采纳答案by Evgeny Karkan

  • On your GitHubprofile there is an Edit Profilebutton.
    It is located on top-right corner of the webpage.
  • Press it and you will see left Personal Settingsmenu.
  • Inside that menu find SSH and GPG keysoption and press it.
  • You will see an option New SSH keyto add new key.
  • 在您的GitHub个人资料上有一个Edit Profile按钮。
    它位于网页的右上角。
  • 按下它,您将看到左侧Personal Settings菜单。
  • 在该菜单中找到SSH and GPG keys选项并按下它。
  • 您将看到New SSH key添加新密钥的选项。

回答by Shravan40

  1. Generate SSH key using ssh-keygen -t rsa -b 4096 -C "your email".
  2. Copy the output of cat ~/.ssh/id_rsa.pubto your clipboard
  3. Paste the above copied output to the form at https://github.com/settings/ssh/new
  1. 使用 生成 SSH 密钥ssh-keygen -t rsa -b 4096 -C "your email"
  2. 将 的输出复制cat ~/.ssh/id_rsa.pub到剪贴板
  3. 将上面复制的输出粘贴到https://github.com/settings/ssh/new的表单中

回答by Waldeyr Mendes da Silva

  1. generate your key

    ssh-keygen

  2. Visualize your keys

    ls ~/.ssh

    id_rsa id_rsa.pub

  3. Start the agent

    eval ssh-agent

  4. Add your key to the agent

    ssh-add ~/.ssh/id_rsa

  1. 生成您的密钥

    ssh-keygen

  2. 可视化你的钥匙

    ls ~ / .ssh

    id_rsa id_rsa.pub

  3. 启动代理

    评估 ssh-agent

  4. 将您的密钥添加到代理

    ssh 添加 ~/.ssh/id_rsa

回答by Waqleh

For me I had to set what host to use what SSH key. In your local machine SSH folder, usually under ~/.sshcreate/edit the file called configusing your preferred editor like vimor gedit

对我来说,我必须设置什么主机使用什么 SSH 密钥。在您本地机器的 SSH 文件夹中,通常在~/.ssh创建/编辑config使用您喜欢的编辑器(如vimgedit)调用的文件下

vim ~/.ssh/config

and add the following with your git Host, HostName, and ssh IdentityFile(your ssh private key file path):

并在您的 git HostHostName和 ssh IdentityFile(您的 ssh 私钥文件路径)中添加以下内容:

Host gitlab.example.com
    HostName gitlab.example.com
    IdentityFile /home/YOURUSERNAME/.ssh/id_rsa

回答by shrillshr

I was having the same problem with my ssh connection. I tried to work it through ssh, but couldn't find a working solution for it. So, in that case, I changed my remote URL from SSH to HTTPS. I used the command: $ git remote set-url origin https://github.com/USERNAME/REPOSITORY.git. You can see your remote url changed using: $ git remote -v.

我的 ssh 连接遇到了同样的问题。我试图通过 ssh 解决它,但找不到可行的解决方案。因此,在这种情况下,我将远程 URL 从 SSH 更改为 HTTPS。我使用了命令: $ git remote set-url origin https://github.com/USERNAME/REPOSITORY.git. 您可以使用以下命令查看远程 url 的更改: $ git remote -v

You can find more detail on Here

您可以在此处找到更多详细信息

This will change your remote URL to HTTPS so you will now have to type your GitHub username and password to push your project to the remote repo. I know ssh is easier than HTTPS meaning that you don't have to type out your username and password, but this might be helpful if you didn't find any solution for fixing it through ssh, and you are in a rush to push your code to your repo.

这会将您的远程 URL 更改为 HTTPS,因此您现在必须键入您的 GitHub 用户名和密码才能将您的项目推送到远程存储库。我知道 ssh 比 HTTPS 更容易,这意味着您不必输入您的用户名和密码,但是如果您没有找到任何通过 ssh 修复它的解决方案,这可能会有所帮助,并且您急于推送您的代码到您的回购。

回答by nk07

If any of you facing same kind of issue on Bitbucket then here is the solution:

如果你们中的任何人在 Bitbucket 上遇到同样的问题,那么这里是解决方案:

Issue:
------

Demo@L90TQCLQ MINGW64 /u/works (master) $ git clone ssh://[email protected]:5449/rem/jenkinspipeline.git Cloning into 'jenkinspipeline'... [email protected]: Permission denied (publickey). fatal: Could not read from remote repository.

问题:
------

Demo@L90TQCLQ MINGW64 /u/works (master) $ git clone ssh://[email protected]:5449/rem/jenkinspipeline.git Cloning into 'jenkinspipeline'.. . [email protected]权限被拒绝(公钥)。致命:无法从远程存储库读取

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

请确保您拥有正确的访问权限并且存储库存在。

Solution:
Demo@L90TQCLQ MINGW64 /u/works (master) $ cat < ~/.ssh/id_rsa.pub ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC99aqMXtBpVvCQb6mezTHsftC3CFY9VOpGaNmckmcTzXoOOWOheeM9V2NTrOWxpbE3UNdL/6ZnmPyv5EI2zPMPstVIP5jAqcmxOvGc2zxy4wHeGTgrP6UaXs2nLScV4E7+rmdaVtSsfOa1i+eU2eg4UnIJpRLtGD6N+hMKJXaXWpGfQ79USiPhPQKDGOz3PeEDggyvHs7HUzaKZpwEeIKYOSDXsvDwTJ6s5uQ30YfX3eoQbAis8TJeQejAmkuu62oSOs5zFJMSTAzakiyXW/xCUsLrnUSzxmBKO2BIA/tSTrqW/Gj0VhDniDFGwGz0K1NfLzfEJLWKvdB2EJWVFjEd [email protected]

解决方案:
演示@ L90TQCLQ MINGW64 / U /工程(主)$猫<的〜/ .ssh / id_rsa.pub支持SSH-RSA AAAAB3NzaC1yc2EAAAADAQABAAABAQC99aqMXtBpVvCQb6mezTHsftC3CFY9VOpGaNmckmcTzXoOOWOheeM9V2NTrOWxpbE3UNdL / 6ZnmPyv5EI2zPMPstVIP5jAqcmxOvGc2zxy4wHeGTgrP6UaXs2nLScV4E7 + rmdaVtSsfOa1i + eU2eg4UnIJpRLtGD6N + hMKJXaXWpGfQ79USiPhPQKDGOz3PeEDggyvHs7HUzaKZpwEeIKYOSDXsvDwTJ6s5uQ30YfX3eoQbAis8TJeQejAmkuu62oSOs5zFJMSTAzakiyXW / xCUsLrnUSzxmBKO2BIA / tSTrqW / Gj0VhDniDFGwGz0K1NfLzfEJLWKvdB2EJWVFjEd [email protected]

Goto: https://bitbucket.internal.abc.com/plugins/servlet/ssh/projects/REM/repos/jenkinspipeline/keys1) Add keys Copy/paste the id_rsa.pub key value there:

转到:https: //bitbucket.internal.abc.com/plugins/servlet/ssh/projects/REM/repos/jenkinspipeline/keys1) 添加密钥复制/粘贴 id_rsa.pub 密钥值:

enter image description here
Done! Now you can able to clone the git repository

在此处输入图片说明
完毕!现在您可以克隆 git 存储库

KDemo@L90TQCLQ MINGW64 /u/works (master) $ git clone ssh://[email protected]:5449/rem/jenkinspipeline.git Cloning into 'jenkinspipeline'... remote: Enumerating objects: 1146, done. remote: Counting objects: 100% (1146/1146), done. remote: Compressing objects: 100% (987/987), done. remote: Total 1146 (delta 465), reused 0 (delta 0) Receiving objects: 100% (1146/1146), 149.53 KiB | 172.00 KiB/s, done. Resolving deltas: 100% (465/465), done.

KDemo@L90TQCLQ MINGW64 /u/works (master) $ git clone ssh://[email protected]:5449/rem/jenkinspipeline.git Cloning into 'jenkinspipeline'... 远程:枚举对象:1146,完毕。远程:计数对象:100% (1146/1146),完成。远程:压缩对象:100% (987/987),完成。远程:总计 1146 (delta 465),重用 0 (delta 0) 接收对象:100% (1146/1146),149.53 KiB | 172.00 KiB/s,完成。解析增量:100% (465/465),完成。

回答by Blusteel408

In my short experience using git with linux, I found there were two simple answers to this error.

在我在 linux 上使用 git 的短暂经验中,我发现这个错误有两个简单的答案。

run these commands in this order

按此顺序运行这些命令

git remote set-url --add origin <https://github.com/username/repo>
git remote set-url --delete origin <[email protected]:username/repo>

This will reconfigure your config file to use HTTPS origin instead of SSH.

这将重新配置您的配置文件以使用 HTTPS 源而不是 SSH。

now try running push or pull commands.

现在尝试运行推或拉命令。

OR

或者

Reboot your linux VM (if you're using one) and/or host machine. Rebooting has resolved the issue for me more than once.

重新启动您的 linux VM(如果您正在使用)和/或主机。重新启动不止一次为我解决了这个问题。

回答by Vikas Pandey

  1. make sure you have named the "public key" and "private key" files properly; precisely like "id_rsa" and "id_rsa.pub". This is something that you can find in your users/.ssh folder.

  2. add the public key in GitHub

  3. Restart your terminal ( bash supported) and try to clone again

  1. 确保您已正确命名“公钥”和“私钥”文件;就像“id_rsa”和“id_rsa.pub”一样。这可以在 users/.ssh 文件夹中找到。

  2. 在 GitHub 中添加公钥

  3. 重新启动您的终端(支持 bash)并再次尝试克隆

if you have the write access to the repo, you should be good to go after these changes.

如果您有对 repo 的写访问权限,那么您应该很好地进行这些更改。

Talking from experience (after spending an hour), I could not find any info on any forum that stated that we have to explicitly keep the name of the private and public file as mentioned above.

根据经验(花了一个小时后),我在任何论坛上都找不到任何说明我们必须明确保留上述私有和公共文件名称的信息。

Happy coding!

快乐编码!

回答by Ulli H

I got it after wasting a lot of time...

浪费了很多时间才搞定的。。。

In the accepted answer of Shravan40everything was ok, but me idiot added at github.com a new repository with adding a new README.md and this caused the error

Shravan40的公认答案中,一切正常,但我白痴在 github.com 上添加了一个新存储库,并添加了新的 README.md,这导致了错误

 ERROR: Repository not found.
 fatal: Could not read from remote repository.
 Please make sure you have the correct access rights

after a lot of tries, i added a new repository withouta new README.md and everything was ok, but i don′t know the reason. :-( Till yesterday, when on a new try i finally noticed it...

经过多次尝试,我添加了一个没有新 README.md的新存储库,一切正常,但我不知道原因。:-( 直到昨天,当我进行新的尝试时,我终于注意到了...

So my solution in addition to Shravan40s answer is

所以除了 Shravan40s 答案之外,我的解决方案是

enter image description here

在此处输入图片说明

maybe it will help someone...

也许它会帮助某人......