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


当前回答

如果用户未生成之前设置的ssh公私钥对

此信息在聊天上工作,但可以应用于所有其他支持SSH pubkey身份验证的git存储库。(参见[gitolite][1], gitlab或github。)

首先设置您自己的公钥/私钥对集。这 可以使用DSA或RSA,所以基本上你设置的任何密钥都可以工作。 在大多数系统上,您可以使用ssh-keygen。

First you'll want to cd into your .ssh directory. Open up the terminal and run: cd ~/.ssh && ssh-keygen Next you need to copy this to your clipboard. On OS X run: cat id_rsa.pub | pbcopy On Linux run: cat id_rsa.pub | xclip On Windows (via Cygwin/Git Bash) run: cat id_rsa.pub | clip On Windows (Powershell) run: Get-Content id_rsa.pub | Set-Clipboard (Thx to @orion elenzil) Add your key to your account via the website. Finally setup your .gitconfig. git config --global user.name "bob" git config --global user.email bob@... (don't forget to restart your command line to make sure the config is reloaded) That's it you should be good to clone and checkout.

更多信息请访问https://help.github.com/articles/generating-ssh-keys(感谢@Lee Whitney) [1]: https://github.com/sitaramc/gitolite

-

如果用户已经生成了之前设置的ssh公私钥对

检查哪个密钥已被授权在您的github或gitlab帐户设置 确定必须从本地计算机关联哪个相应的私钥

Eval $(ssh agent -s)

定义键的位置

ssh-add ~ / . ssh / id_rsa

其他回答

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

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

我遇到了同样的问题,因为我认为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。

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

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

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

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

在我的ubuntu系统中,我按照下面的步骤解决了这个问题。因为我正在尝试用无密码ssh到系统。

sudo vi /etc/ssh/sshd_config

1)评论如下: #更改为no禁用隧道明文密码 # PasswordAuthentication是的 PasswordAuthentication no ---->注释此。

2)然后重新启动sshd守护进程,如下所示。

重启SSHD服务

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很快就会修复这个问题,但这已经是我第二次在这个问题上浪费时间了。