我正在尝试使用以下命令行将代码部署到heroku:

git push heroku master

但会出现以下错误:

Permission denied (publickey).
fatal: The remote end hung up unexpectedly

我已经上传了我的公共SSH密钥,但仍然会出现此错误。


当前回答

如果要使用“sudo”,例如:

sudo git clone git@heroku.com......... -o heroku

您还应该为root用户生成ssh密钥。

sudo su
cd /root/.ssh  
ssh-keygen -t rsa
....
heroku keys:add id_rsa.pub

它会奏效的。

如果不使用root用户,请在用户目录中生成ssh密钥。

cd /home/user/.ssh

对不起,如果我的句子搞砸了。。。

其他回答

只有一个命令有效:

heroku keys:add

如果它不存在的话,它会成为一个。

推送时使用

git push heroku production:master 

使用主目录~/.ssh/id_rsa下的公钥

要解决此问题

您应该以其他用户身份登录,可能是root用户

sudo su 

然后通过发出以下命令重新开始

heroku keys:clear //removes existing keys
ssh-keygen -t rsa //generates a new key in ~/.ssh folder (set a password)
heroku keys:add   //uploads the new key, ~/.ssh/id_rsa is uploaded                      
git push heroku production:master

我必须这样做:

$ ssh-keygen -t rsa  
$ heroku keys:add  

然后它奏效了:

$ git push heroku master  

要遵循的顺序

$ heroku login
$ ssh-keygen -t rsa
$ heroku keys:add

当执行第二条语句时,它会要求输入,只需按Enter(回车)三次,就会添加一个键。

对于那些在Windows7上尝试了上述所有方法但仍然没有成功的人,我做了以下工作:-从Git目录C:\Program Files(x86)\Git\中打开GitBash.exe(不要打开命令提示符,这不起作用)。-如上所述添加以下内容,但必须删除#

Host heroku.com
Hostname heroku.com 
Port 22 
IdentitiesOnly yes 
IdentityFile ~/.ssh/ssh-dss
TCPKeepAlive yes 
User joe@workstation.local

现在运行gitpushherokumaster,它应该可以工作了。