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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21255438/
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-10 17:36:47  来源:igfitidea点击:

Git: Permission denied (publickey) fatal - Could not read from remote repository. while cloning Git repository

gitgit-clone

提问by KCS

I am unable to clone a Git repository, and getting this error:

我无法克隆 Git 存储库,并收到此错误:

krishna.soni@KRISHNACHANDRAS /c/Projects $ git clone http://stage.abc.com:10088/pqr
http://<url>/<repository> Cloning into '<repository>'... fatal: could not read Username for 'http://<url>': No such file or directory

I've read Bitbucket, Windows and “fatal: could not read Password for”, but still have the problem.

我读过Bitbucket、Windows 和“fatal: could not read Password for”,但仍然有问题。

I proceeded further but am now getting this error

我继续进行,但现在收到此错误

sh.exe": chown: command not found

krishna.soni@KRISHNACHANDRAS /c
$ git clone ssh://[email protected].
/projects
Cloning into 'C:/projects'...
Permission denied (publickey).
fatal: Could not read from remote repository.

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

> krishna.soni@KRISHNACHANDRAS /c
>     $ git clone ssh:<url>
>     ts
>     Cloning into 'C:/projects'...
>     Permission denied (publickey).
>     fatal: Could not read from remote repository.

Please make sure you have the correct access rights

and the repository exists.

并且存储库存在。

采纳答案by First Zero

It looks like a permissions issue - not a Windows 7 issue.

看起来像是权限问题 - 而不是 Windows 7 问题。

Your ssh key is not authorised - Permission denied (publickey).

您的 ssh 密钥未经授权 - Permission denied (publickey).

You need to create a public ssh key and ask the administrator of the Git repository to add the sshpublic key

您需要创建一个公共 ssh 密钥并要求 Git 存储库的管理员添加ssh公共密钥

Information on how to do this: Saving ssh key fails

有关如何执行此操作的信息:保存 ssh 密钥失败

回答by Arjan

For people that come here that are just trying to get the repository but don't care about the protocol (ssh / https), you might just want to use https instead of ssh(if it's supported).

对于来这里只是想获取存储库但不关心协议(ssh / https)的人,您可能只想使用 https 而不是 ssh(如果支持)。

So for example you use

所以例如你使用

git clone https://github.com/%REPOSITORYFOLDER%/%REPOSITORYNAME%.git

instead of

代替

git clone [email protected]:%REPOSITORYFOLDER%/%REPOSITORYNAME%.git

回答by Srikanth Kondaparthy

If there is still issue around access after creating SSH and adding it in your Bitbucket account or wherever, you need to do the following in terminal on GitBash, OSX or Linux:

如果在创建 SSH 并将其添加到您的 Bitbucket 帐户或其他任何地方后访问仍然存在问题,您需要在 GitBash、OSX 或 Linux 的终端中执行以下操作:

# Lists already added identities (‘ssh keys')
ssh-add -l

Then, if you don't see your key listed, add it with the following (replace identitywith its real name):

然后,如果您没有看到您的密钥列出,请添加以下内容(替换identity为真实姓名):

# Add a new identity
ssh-add ~/.ssh/identity

This worked for me.

这对我有用。

回答by Maxime

I faced the same problem with GitHub. Here's how to solve it!

我在GitHub 上遇到了同样的问题。以下是解决方法!

  1. Generate a SSH key on your computer as described here : Generating SSH keys.
  2. Login your GitHub account: GitHub Login.
  3. In your account, add the newly generated SSH Key: My account SSH keys.
  4. Try again to git clonethe project.
  1. 按照此处所述在您的计算机上生成 SSH 密钥生成 SSH 密钥
  2. 登录您的 GitHub 帐户:GitHub 登录
  3. 在您的帐户中,添加新生成的 SSH 密钥:我的帐户 SSH 密钥
  4. 再试一下git clone项目。

回答by eithed

I've had this issue on a Mac - while I setup SSH correctly to access my Git repository, after restart (and some time the Mac was on a standoff), all my credentials were removed. Apparently, for some reason the pub key was set to 644 which caused it to be removed from the keychain. To readd:

我在 Mac 上遇到过这个问题 - 虽然我正确设置了 SSH 以访问我的 Git 存储库,但在重新启动后(并且有一段时间 Mac 处于僵局状态),我的所有凭据都被删除了。显然,由于某种原因,pub 密钥被设置为 644,这导致它从钥匙串中删除。阅读:

  • chmod 600the public key
  • ssh-add ~/.ssh/[your private key]- this should display that identity has been added. The key file you want is the one without the .pub extension.
  • ssh-add -lshould show you newly added identity
  • chmod 600公钥
  • ssh-add ~/.ssh/[your private key]- 这应该显示已添加身份。您想要的密钥文件是没有 .pub 扩展名的文件。
  • ssh-add -l应该向您显示新添加的身份

edit: apparently MacOS has tendency of removing keys - after downloading the High Sierra update (but I've not installed it yet) my key has been removed and I've had to add it again via ssh-add

编辑:显然 MacOS 有删除密钥的趋势 - 在下载 High Sierra 更新(但我还没有安装它)后,我的密钥已被删除,我不得不通过以下方式再次添加它 ssh-add

回答by Ashwin Tumma

I also faced the same issue. I did the following and it worked for me:

我也面临同样的问题。我做了以下工作,它对我有用:

  1. Generate Keys from the GIT GUI client on Windows. Copy this key to the clipboard.
  2. Open up your account on bitBucket/git website, and add this key to your profile. This way, the server knows that you are a legitimate user accessing from a legitimate system.
  3. That's it. All push commands worked for me henceforth.
  1. 从 Windows 上的 GIT GUI 客户端生成密钥。将此密钥复制到剪贴板。
  2. bitBucket/git 网站上打开您的帐户,并将此密钥添加到您的个人资料中。这样,服务器就知道您是从合法系统访问的合法用户。
  3. 就是这样。此后所有推送命令都对我有用。

回答by jsxqf

Github(or Bitbucket) can't find your ssh key in their server.

Github(或 Bitbucket)在他们的服务器中找不到你的 ssh 密钥。

Just add your key in your account setting.

只需在您的帐户设置中添加您的密钥。

回答by mustapha

For me, when i wanted to clonefrom my repository, i had the same message noticed before "Permission denied (publickey) fatal: Could not read from remote repository". The solution for my case is to not use sudo before cloneThat's it.

对我来说,当我想从我的存储库克隆时,我在“权限被拒绝(公钥)致命:无法从远程存储库读取”之前注意到了相同的消息。我的情况的解决方案是在克隆之前不使用 sudo就是这样。

回答by nicolas asinovich

If you generate new public ssh key and inserted it to bitbucket or github and

如果您生成新的公共 ssh 密钥并将其插入到 bitbucket 或 github 和

it not helped - please try to restart your PC. It helped me!!

它没有帮助 -请尝试重新启动您的 PC。它帮助了我!!

回答by biniam

You need to create a new ssh key by running ssh-keygen -t rsa.

您需要通过运行创建一个新的 ssh 密钥ssh-keygen -t rsa