我用的是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 -vT git@github.com

或者,根据以下意见,我们可以发出:

ssh -vT git@gitlab.com

或者用你的组织正在运行的Git实例替换gitlab/github。

来源:https://help.github.com/articles/error-permission-denied-publickey/

其他回答

如果用户未生成之前设置的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

更广泛的故障排除,甚至自动修复可以完成:

ssh -vT git@github.com

或者,根据以下意见,我们可以发出:

ssh -vT git@gitlab.com

或者用你的组织正在运行的Git实例替换gitlab/github。

来源:https://help.github.com/articles/error-permission-denied-publickey/

我必须将ssh密钥复制到根文件夹。 谷歌云计算引擎,Ubuntu 18.04

sudo cp ~/.ssh/* /root/.ssh/

你是在公司工作吗?有没有可能您的系统变量最近发生了变化?根据这个SO回答,ssh密钥位于%HOMEDRIVE%%HOMEPATH%\.ssh\id_rsa.pub。因此,如果%HOMEDRIVE%最近发生了更改,git就不知道到哪里去查找密钥,因此就无法进行所有的身份验证。

尝试运行ssh -vT git@github.com。注意身份文件的位置。对我来说,这不是指向我的普通的\Users\MyLogin,而是指向一个网络驱动器,因为在网络级别上推了一个环境变量的变化。

解决方案?由于我的新%HOMEDRIVE%与我的本地文件具有相同的权限,我只是将.ssh文件夹移到那里,然后就结束了。

同样的错误报告。

修正了使用HTTPS而不是SSH协议的问题。因为我不想为测试PC设置“SSH密钥”。

克隆时将URL更改为HTTPS:

git clone https://github.com/USERNAME/REPOSITORY.git

我的问题有点不同:当添加一个现有的本地回购到远程时,我有URL设置为SSH,通过使用:

git remote add origin ssh://github.com/USERNAME/REPOSITORY.git

要解决这个问题,请将URL重置为HTTPS:

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

顺便说一句,你可以使用命令检查你的URL:

git remote -v
origin  https://github.com/USERNAME/REPOSITORY.git (fetch)
origin  https://github.com/USERNAME/REPOSITORY.git (push)

希望这能帮助到像我这样的人。: D