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


当前回答

伙计们我是这么干的

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之类的命令,那么您将不会使用您生成的相同密钥

其他回答

使用来自Github的ssh链接,但确保不要附加ssh,只需使用git hub上的ssh选项卡来克隆你的repo。

当你试图用不同的用户名推送到存储库时,最简单的解决方案是:

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

基本的GIT指令没有引用SSH密钥之类的东西。沿着上面的一些链接,我发现了一个git帮助页面,它一步一步地解释了如何在各种操作系统上做到这一点(链接将检测您的操作系统并相应地重定向):

http://help.github.com/set-up-git-redirect/

它介绍了GITHub所需的所有内容,并给出了详细的解释,例如“为什么在创建RSA密钥时添加密码短语”。我想我应该把它贴出来,说不定能帮助到别人……

可能是public/private配置不正确。请按照步骤来做。 在窗口任意位置执行命令

ssh-keygen -o -f ~/.ssh/id_rsa

现在转到c://users/xyz/。Ssh /打开id_rsa密钥(路径可能不同) 现在转到gitlab和用户配置文件>设置>ssh密钥,并在这里添加您的密钥。 现在试试克隆

我遇到了同样的问题,因为我认为SSH和HTTPS之间的区别是

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

ssh: / / github.com/USERNAME/REPOSITORY.git

因此,我从HTTPS更改为SSH,只需将https://更改为SSH:// url的末尾没有任何变化。

但事实是:

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

git@github.com:USERNAME/REPOSITORY.git

这意味着我将ssh://github.com/USERNAME/REPOSITORY.git更改为git@github.com:USERNAME/REPOSITORY.git。

愚蠢的错误,但希望能帮助某人!