Git:如何解决使用 Git 时的 Permission denied (publickey) 错误?

标签 git ssh ssh-keys public-key

我在 Mac Snow Leopard 上,我刚刚安装了 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 没有 passphase 但仍然有同样的错误。

最佳答案

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

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

First start by setting up your own public/private key pair set. This can use either DSA or RSA, so basically any key you setup will work. On most systems you can use ssh-keygen.

  • First you'll want to cd into your .ssh directory. Open up the terminal and run:

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)
  • 通过网站将您的 key 添加到您的帐户。
  • 最后设置您的 .gitconfig。
  • git config --global user.name "bob"
  • git config --global user.email bob@... (不要忘记重新启动命令行以确保重新加载配置)

就是这样,您应该做好克隆和 checkout 的准备。

可以在 https://help.github.com/articles/generating-ssh-keys 找到更多信息。 (感谢@Lee Whitney) [1]: https://github.com/sitaramc/gitolite

-

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

  • 在你的github或gitlab账户设置中检查哪些 key 已经被授权
  • 确定必须从您的本地计算机关联哪个对应的私钥

eval $(ssh-agent -s)

  • 定义键的位置

ssh-add ~/.ssh/id_rsa

关于Git:如何解决使用 Git 时的 Permission denied (publickey) 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2643502/

相关文章:

Git 归咎于重组的 SVN 存储库

git - 带有两个 git 存储库的 Jenkinsfile

java - JSch 没有检测到 $HOME/.ssh/id_rsa 公钥

git - 将 "proxies"与 git 一起使用

git - 我如何使用 Git 作为一次提交 rebase

git - 在 git 上重命名文件并保留历史记录

ssh - Camel sftp 端点在哪里期望 known_hosts 文件?

security - 基于ssh key 的网站访问?

encryption - ssh-keygen 和 openssl 给出两个不同的公钥

Jenkins CLI : ERROR: anonymous is missing the Overall/Read permission