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


当前回答

在GitHub中使用终端添加RSA密钥:

MAC:

进入Users/ xxxx /.ssh文件夹 执行命令:cd ~/。ssh && ssh-keygen -t ed25519 -C "github_email@id.com" 输入文件名为id_rsa 输入if ask口令 再次输入 运行eval "$(ssh-agent -s)" 打开配置文件:Open ~/.ssh/config 如果不存在,则创建为: 触碰~ / . ssh / config 现在打开配置文件,并在文件中添加以下行:

主机* AddKeysToAgent是的 UseKeychain是的 IdentityFile ~ / . ssh / id_rsa

关闭文件 为agent run命令添加ssh私钥。 ssh-add -K ~/.ssh/id_rsa . sh 现在复制ssh密钥为: Pbcopy < ~/.ssh/id_rsa.pub 去gitHub/BitBucket 点击管理帐户 点击SSH键 删除现有密钥 点击添加键 粘贴复制的密钥。

其他回答

我碰到了这个错误,因为我需要给我目前的工作目录权限700:

chmod -R 700 /home/ec2-user/

我正与同样的问题作斗争,这就是我所做的,我能够克隆回购。我在Mac上遵循了这个步骤。

第一步:检查我们是否已经拥有公共SSH密钥。

打开终端。 输入ls -al ~/。查看是否存在现有的ssh密钥:

检查目录列表,查看是否已经拥有公共SSH密钥。默认public是以下d_dsa之一。酒吧,id_ecdsa。酒吧,id_ed25519。酒吧,id_rsa . pub。

如果你没有找到,那么转到步骤2,否则继续步骤3

步骤2:生成SSH公钥

Open Terminal. Enter the following command with a valid email address that you use for github ssh-keygen -t rsa -b 4096 -C "your_email@example.com" You will see the following in your terminal Generating public/private rsa key pair. When it prompts to"Enter a file in which to save the key," press Enter. This accepts the default file location. When it prompts to Enter a file in which to save the key (/Users/you/.ssh/id_rsa): [Press enter] Just press enter again. At the prompt, "Type a secure passphrase. Enter passphrase (empty for no passphrase): [Type a passphrase]" press enter if you don't want to Enter same passphrase again: [Type passphrase again] press enter again

这将生成id_rsa.pub

步骤3:添加SSH密钥到SSH -agent

Interminal type eval "$(ssh-agent -s)" Add your SSH key to the ssh-agent. If you are using an existing SSH key rather than generating a new SSH key, you'll need to replace id_rsa in the command with the name of your existing private key file. Enter this command $ ssh-add -K ~/.ssh/id_rsa Now copy the SSH key and also add it to you github account In terminal enter this command with your ssh file name pbcopy < ~/.ssh/id_rsa.pub This will copy the file to your clipboard Now open you github account Go to Settings > SSH and GPG keys > New SSH key Enter title and paste the key from clipboard and save it. Voila you're done.

我刚刚在设置我当前的项目时遇到了这个问题,上面的解决方案都不起作用。所以我试着用命令ssh -vT git@github.com查看调试列表上到底发生了什么。我注意到我的私钥文件名不在列表中。因此,将私钥文件名重命名为'id_rsa'就可以了。希望这能有所帮助。

在我的例子中,这个奇怪的错误是gnome-keyring-daemon错误地命名了需要密码的密钥的症状。

我按照这里列出的步骤,并通过终端输入密码。这个错误,也就是混乱的GUI界面,已经解决了。 参见:https://askubuntu.com/questions/3045/how-to-disable-gnome-keyring

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

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

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