我用的是Mac雪豹,刚刚安装了git。

我只是试了

git clone git@thechaw.com:cakebook.git

但这给了我这个错误:

Initialized empty Git repository in `/Users/username/Documents/cakebook/.git/`
Permission denied (publickey).
fatal: The remote end hung up unexpectedly

我错过了什么? 我也试过做ssh-keygen没有密码,但仍然错误。


当前回答

如果没有解决问题,请尝试一下

生成个人访问令牌(设置->开发人员设置->个人访问令牌->生成新的令牌) git remote set-url origin https://<TOEKN>@github.com/USERNAME/REPOSITORY.git

注意:如果弹出密码窗口,请尝试只输入令牌(尝试两次)

其他回答

这就是我如何最终能够推动git


对我来说,我一直在得到

git@github.com: Permission denied 
fatal: Could not read from remote 

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

所以经过几个小时的研究,我发现在生成您的ssh密钥并使您的windows代理识别您的密钥后,我做的最后一件事来解决我的问题是更新ssh密钥在git回购的项目。

你可以登录到你的git hub账户,然后进入你想要推送的repo,然后在设置中寻找安全性,在那里你可以添加ssh密钥。对于我来说,密钥存储在.ssh/id_ed123939.pub中

视觉指南(Windows)

1 / 2。Git批处理端

1.1. 打开git批处理(下载她)

1.2. 粘贴下面的文本(更改到您的GitHub帐户电子邮件)

$ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

1.3. 按Enter(接受默认文件位置)

1.4. 单击Enter两次(或设置SSH密钥passphrases - Gitbub passphrases docs)

> Enter passphrase (empty for no passphrase): [Type a passphrase]
> Enter same passphrase again: [Type passphrase again]

1.5. 键生成:

您的身份信息已保存在/c/Users/user/.ssh/id_rsa…

1.6. 将SSH密钥复制到剪贴板。

$ clip < ~/.ssh/id_rsa.pub

2 / 2。Github网站用户端

在用户设置下

SSH和GPG密钥=>新的SSH密钥:

粘贴步骤1.6中的代码

:完成)


如果有人不想使用SSH,请使用HTTPS:

Github docs: https://docs.github.com/en/github/authenticating-to-github/connecting-to-github-with-ssh

我今天在尝试使用git bash在windows中设置一个现有的存储库时遇到了这个问题。问题出现在输入以下内容时:

git clone myreposshurl

在gitbash中,ctrl+c和ctrl+v不起作用。在尝试粘贴存储库url时,我按了ctrl+v,这引入了一些不需要的字符。当我尝试并成功克隆另一个存储库时,终于发现并解决了这个问题。花了一个半小时才发现这个愚蠢的错误。

\302\226git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

如果你看到像上面这样的\302字符,那么这可能是一个可能的原因。

解决方案使用gh即Github的官方CLI

gh安装

Brew install gh

通过cli登录或认证

Gh auth登录

回购克隆

Gh repo clone <username or orgname>/<repo-name> . sh

例如:gh repo clone keshavdulal/sample-repo

咆哮:当git克隆突然决定不再工作时,我也在敲打我的头,我没有耐心或脑力从头开始重新学习ssh/公钥/密密学,只是为了克隆一个我已经可以访问的该死的回购。同样令人惊讶的是,答案中还没有人提到gh

更广泛的故障排除,甚至自动修复可以完成:

ssh -vT git@github.com

或者,根据以下意见,我们可以发出:

ssh -vT git@gitlab.com

或者用你的组织正在运行的Git实例替换gitlab/github。

来源:https://help.github.com/articles/error-permission-denied-publickey/