我用的是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没有密码,但仍然错误。


当前回答

我也犯了同样的错误。

问题是,当将公钥复制到BitBucket(在我的情况下)时,在末尾复制/粘贴了一个不可见的换行符。

因此,在复制公钥时,首先将其复制到记事本,删除末尾的空行,复制并粘贴。

其他回答

您可以在终端中执行以下操作:

cd ~ / . ssh ssh-keygen -o -t rsa -C "your@email.com" 当提示输入密钥保存位置时,输入:cat id_rsa。Pub | pbcopy 输入并确认您的密码,然后生成新的密钥。 通过运行cat ~/.ssh/id_rsa.pub通知github密钥 复制输出,然后转到github创建一个新的SSH密钥。粘贴复制的内容到文本区域,给它一个合适的标题,然后按ADD键。

现在你可以轻松地进行操作了。

当您正在访问SSH URL(读/写)而不是Git只读URL,但您没有对该repo的写访问权限时,可能会发生此错误。

有时你只是想克隆你自己的repo,例如部署到服务器上。在这种情况下,实际上只需要READ-ONLY访问。但由于这是你自己的回购,GitHub可能会显示SSH URL,如果这是你的偏好。在这种情况下,如果您的远程主机的公钥不在您的GitHub SSH密钥中,您的访问将被拒绝,这是预期会发生的。

一个等效的情况是,当您尝试克隆其他人的回购时,您没有SSH URL的写访问权。

总之,如果您的意图是只克隆一个repo,请使用HTTPS URL (https://github.com/{user_name}/{project_name}.git)而不是SSH URL (git@github.com:{user_name}/{project_name}.git),这样可以避免(不必要的)公钥验证。


更新:GitHub现在显示HTTPS作为默认协议,这一举动可能会减少SSH url的滥用。

伙计们我是这么干的

Open terminal and go to user [See attached image] Open .ssh folder and make sure it doesn't have any file like id_rsa or id_rsa.pub otherwise sometimes it wont properly rewrite files git --version [Check for git installation and version] git config --global user.email "your email id" git config --global user.name "your name" git config --list [make sure you have set your name & email] cd ~/.ssh ssh-keygen, it prompts for saving file, allow it cat ~/.ssh/id_rsa.pub [Access your public key & copy the key to gerrit settings]

注意:你不应该在Git中使用sudo命令。如果您有非常好的理由必须使用sudo,那么请确保您在每个命令中都使用它(此时使用su作为根来获取shell可能更好)。如果您不使用sudo生成SSH密钥,然后尝试使用sudo git push之类的命令,那么您将不会使用您生成的相同密钥

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

生成个人访问令牌(设置->开发人员设置->个人访问令牌->生成新的令牌) 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中