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


当前回答

这很直接。键入下面的命令

ssh-keygen -t rsa -b 4096 -C "youremailid@yourdomain.com"

生成SSH密钥。打开文件并复制内容。进入GitHub设置页面,点击SSH key。单击“添加新的SSH密钥”,并将内容粘贴到此处。就是这样:)你不应该再看到这个问题了。

其他回答

伙计们我是这么干的

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


对我来说,我一直在得到

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中

同样的错误报告。

修正了使用HTTPS而不是SSH协议的问题。因为我不想为测试PC设置“SSH密钥”。

克隆时将URL更改为HTTPS:

git clone https://github.com/USERNAME/REPOSITORY.git

我的问题有点不同:当添加一个现有的本地回购到远程时,我有URL设置为SSH,通过使用:

git remote add origin ssh://github.com/USERNAME/REPOSITORY.git

要解决这个问题,请将URL重置为HTTPS:

git remote set-url origin https://github.com/USERNAME/REPOSITORY.git

顺便说一句,你可以使用命令检查你的URL:

git remote -v
origin  https://github.com/USERNAME/REPOSITORY.git (fetch)
origin  https://github.com/USERNAME/REPOSITORY.git (push)

希望这能帮助到像我这样的人。: D

解决方案使用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-keygen -t rsa -b 4096 -C "youremailid@yourdomain.com"

生成SSH密钥。打开文件并复制内容。进入GitHub设置页面,点击SSH key。单击“添加新的SSH密钥”,并将内容粘贴到此处。就是这样:)你不应该再看到这个问题了。