我用的是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://USERNAME@github.com/USERNAME/PROJECTNAME.git

其他回答

完成ssh-keygen部分后,您可以通过以下方式检查验证:

$ ssh -T git@github.com用于测试ssh连接; 确认是哪个用户执行了ssh-keygen命令。您生成的公钥后面跟着该用户。原因如下:

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

确认您对存储库将克隆到的目录具有写权限。如果没有,那就去做。更新用户组权限后,必须通过注销或su等方式刷新当前用户。

我正与同样的问题作斗争,这就是我所做的,我能够克隆回购。我在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-keygen -t rsa -b 4096 -C "youremailid@yourdomain.com"

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

对我来说,问题是使用sudo:

sudo git克隆git@github.com:userName/repo.git导致上述错误。

所以为了解决这个问题,我咀嚼了我试图克隆到的文件夹

sudo chown -R $USER:$USER /var/www/iqge.org/html

然后用这个 git克隆git@github.com:userName/repo.git was successfully done

对我来说,实际的问题是使用文本编辑器复制SSH公钥到剪贴板

如果按照docs.github.com,在notepad++等文本编辑器中打开。pub文件复制SSH公钥,那么就有麻烦了。

而不是使用

猫~ / . ssh / id_ * * *。Pub |剪辑

复制命令