本文介绍了Git:如何解决使用 Git 时的 Permission denied (publickey) 错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 Mac Snow Leopard 并且我刚刚安装了 git.

我刚试过

git clone [email protected]:cakebook.git

但这给了我这个错误:

在`/Users/username/Documents/cakebook/.git/`中初始化空的Git仓库权限被拒绝(公钥).致命:远端意外挂断

我错过了什么?
我也试过在没有密码的情况下执行 ssh-keygen 但仍然出现相同的错误.

解决方案

如果用户之前没有生成ssh公钥/私钥对

此信息适用于 theChaw,但可以应用于所有其他支持 SSH 公钥身份验证的 git 存储库.(例如参见 [​​gitolite][1]、gitlab 或 github.)

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

  • 首先,您需要 cd 进入您的 .ssh 目录.打开终端并运行:

cd ~/.ssh &&ssh-keygen

  • 接下来,您需要将其复制到剪贴板.
  • 在 OS X 上运行:cat id_rsa.pub |pbcopy
  • 在 Linux 上运行:cat id_rsa.pub |xclip
  • 在 Windows 上(通过 Cygwin/Git Bash)运行:cat id_rsa.pub |剪辑
  • 在 Windows (Powershell) 上运行:Get-Content id_rsa.pub |设置剪贴板(感谢@orion elenzil)
  • 通过网站将您的密钥添加到您的帐户.
  • 最后设置您的 .gitconfig.
  • git config --global user.name bob"
  • git config --global user.email bob@...(不要忘记重新启动命令行以确保重新加载配置)

就是这样,您应该可以很好地克隆和结帐.

更多信息可以在 https://help.github.com/articles/生成 ssh 密钥(感谢@Lee Whitney)[1]:https://github.com/sitaramc/gitolite

-

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

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

eval $(ssh-agent -s)

  • 定义密钥所在的位置

ssh-add ~/.ssh/id_rsa

I'm on Mac Snow Leopard and I just installed git.

I just tried

git clone [email protected]:cakebook.git

but that gives me this error:

Initialized empty Git repository in `/Users/username/Documents/cakebook/.git/`
Permission denied (publickey).
fatal: The remote end hung up unexpectedly

What am I missing?
I've also tried doing ssh-keygen with no passphase but still same error.

解决方案

If the user has not generated a ssh public/private key pair set before

This info is working on theChaw but can be applied to all other git repositories which support SSH pubkey authentications. (See [gitolite][1], gitlab or github for example.)

  • 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.

Further information can be found at https://help.github.com/articles/generating-ssh-keys (thanks to @Lee Whitney)[1]: https://github.com/sitaramc/gitolite

-

If the user has generated a ssh public/private key pair set before

  • check which key have been authorized on your github or gitlab account settings
  • determine which corresponding private key must be associated from your local computer

eval $(ssh-agent -s)

  • define where the keys are located

ssh-add ~/.ssh/id_rsa

这篇关于Git:如何解决使用 Git 时的 Permission denied (publickey) 错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 09:20