我用的是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上的另一种可能性,在这些答案中都没有涉及,git或github文档中也没有涉及故障排除:
Git使用的openssh可执行文件可能与您认为的不同。
当我试图从github和ssh.dev.azure.com克隆或拉时,我收到了权限拒绝(公钥)错误,我遵循了所有的说明,并验证我的SSH密钥被正确设置(从SSH的立场)使用SSH -vT git@github.com和SSH -vT git@ssh.dev.azure.com。并且仍然得到这些错误:
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
我最终发现问题在于Git for Windows和Windows都有自己的openssh版本。这里有文档:https://github.com/desktop/desktop/issues/5641
我依赖于Windows的ssh-agent服务来存储我的ssh密钥密码,所以git(使用它的单独版本的openssh)无法读取我的私钥。我认为这是一个错误,这个错误信息被使用-它是误导性的。
解决方案是:
git config --global core.sshCommand "'C:\Windows\System32\OpenSSH\ssh.exe'"
或者在~/.gitconfig中:
[core]
sshCommand = 'C:\\Windows\\System32\\OpenSSH\\ssh.exe'
也许git很快就会修复这个问题,但这已经是我第二次在这个问题上浪费时间了。
视觉指南(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