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


当前回答

视觉指南(Windows)

1 / 2。Git批处理端

1.1. 打开git批处理(下载她)

1.2. 粘贴下面的文本(更改到您的GitHub帐户电子邮件)

$ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

1.3. 按Enter(接受默认文件位置)

1.4. 单击Enter两次(或设置SSH密钥passphrases - Gitbub passphrases docs)

> Enter passphrase (empty for no passphrase): [Type a passphrase]
> Enter same passphrase again: [Type passphrase again]

1.5. 键生成:

您的身份信息已保存在/c/Users/user/.ssh/id_rsa…

1.6. 将SSH密钥复制到剪贴板。

$ clip < ~/.ssh/id_rsa.pub

2 / 2。Github网站用户端

在用户设置下

SSH和GPG密钥=>新的SSH密钥:

粘贴步骤1.6中的代码

:完成)


如果有人不想使用SSH,请使用HTTPS:

Github docs: https://docs.github.com/en/github/authenticating-to-github/connecting-to-github-with-ssh

其他回答

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

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

这对我很有效

ssh -i [your id_rsa path] -T github@github.com

视觉指南(Windows)

1 / 2。Git批处理端

1.1. 打开git批处理(下载她)

1.2. 粘贴下面的文本(更改到您的GitHub帐户电子邮件)

$ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

1.3. 按Enter(接受默认文件位置)

1.4. 单击Enter两次(或设置SSH密钥passphrases - Gitbub passphrases docs)

> Enter passphrase (empty for no passphrase): [Type a passphrase]
> Enter same passphrase again: [Type passphrase again]

1.5. 键生成:

您的身份信息已保存在/c/Users/user/.ssh/id_rsa…

1.6. 将SSH密钥复制到剪贴板。

$ clip < ~/.ssh/id_rsa.pub

2 / 2。Github网站用户端

在用户设置下

SSH和GPG密钥=>新的SSH密钥:

粘贴步骤1.6中的代码

:完成)


如果有人不想使用SSH,请使用HTTPS:

Github docs: https://docs.github.com/en/github/authenticating-to-github/connecting-to-github-with-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

除了Rufinus的回复,在Windows中将ssh密钥复制到剪贴板的快捷方式是:

id_rsa类型。Pub |剪辑

参考文献:

打印到标准输出 复制命令行输出到剪贴板