当通过Ruby脚本克隆Bitbucket仓库时出现“Permission denied (publickey)”错误。

4
经过几个小时的问题、大量的谷歌搜索和众多的配置更改,我现在请求你的帮助。
我想在我的运行在Ubuntu 12.04服务器下的Redmine 2.3服务器上为我的私有仓库使用Redmine Bitbucket插件https://bitbucket.org/steveqx/redmine_bitbucket
我已经安装并成功地配置了Bitbucket以进行更新本地存储库的POST请求。但是我收到以下错误:
BitbucketPlugin: Command 'git clone --mirror git@bitbucket.org:xxxxxxx/yyyyyyyy.git bitbucket_repos/projectxyz/xxxxxxx/yyyyyyyyy' didn't exit properly. Full output: ["Cloning into bare repository 'bitbucket_repos/projetxyz/xxxxxxx/yyyyyyyyy'...\n", "Permission denied (publickey).\r\n", "fatal: The remote end hung up unexpectedly\n"]

因为我正在使用mod_passenger运行Redmine,所以我在/var/www/.ssh/id_rsa下为该用户添加了ssh密钥。
当我运行
sudo -u www-data git clone git@bitbucket.org:xxxxxxx/yyyyyyyyy.git

它工作了。当我运行时

sudo -u www-data ssh -vvv git@bitbucket.org pwd 2> >(grep -i offer)

我得到:
debug1: Offering RSA public key: /var/www/.ssh/id_rsa

看起来,www-data用户使用了正确的密钥。

这是从Bitbucket进行POST请求后production.log的完整输出:

Started POST "/bitbucket_service?project_id=projectxy" for 131.103.20.166 at 2013-08-04 

19:27:12 +0200
Processing by BitbucketServiceController#index as HTML
  Parameters: {"payload"=>"{\"repository\": {\"website\": \"\", \"fork\": false, \"name\": \"yyyyyyyy\", \"scm\": \"git\", \"owner\": \"xxxxxxx\", \"absolute_url\": \"/xxxxxxx/yyyyyyyy/\", \"slug\": \"yyyyyyyy\", \"is_private\": true}, \"truncated\": false, \"commits\": [{\"node\": \"2d43ec2ad9f3\", \"files\": [{\"type\": \"modified\", \"file\": \"app/controllers/notifications_controller.rb\"}], \"branch\": \"master\", \"utctimestamp\": \"2013-08-04 17:28:33+00:00\", \"timestamp\": \"2013-08-04 19:28:33\", \"raw_node\": \"2d43ec2ad9f3cc2cfbc0190adb14c7e5683df22d\", \"message\": \"Testing on redmine Repo\\n\", \"size\": -1, \"author\": \"xxxxxxx\", \"parents\": [\"0153d1ce7f9f\"], \"raw_author\": \"My Name <my@mail.com>\", \"revision\": null}], \"canon_url\": \"https://bitbucket.org\", \"user\": \"xxxxxxx\"}", "project_id"=>"projectxyz"}
  Current user: anonymous
BitbucketPlugin: Command 'git clone --mirror git@bitbucket.org:xxxxxxx/yyyyyyyy.git bitbucket_repos/projectxyt/xxxxxxx/yyyyyyyy' didn't exit properly. Full output: ["Cloning into bare repository 'bitbucket_repos/projectxyz/xxxxxxx/yyyyyyyy'...\n", "Permission denied (publickey).\r\n", "fatal: The remote end hung up unexpectedly\n"]
  Rendered text template (0.0ms)
Completed 500 Internal Server Error in 1257ms (Views: 1.3ms | ActiveRecord: 2.6ms)

请问我做错了什么?如果需要更多的数据或跟踪,请告诉我。谢谢。
编辑: 我在/var/www/.ssh/config中使用配置文件:
Host *
    User git
    Hostname bitbucket.org
    PreferredAuthentications publickey
    IdentityFile /var/www/.ssh/id_rsa
1个回答

1

好的,经过几天的努力,我自己找到了解决方案。由于配置错误,我的Rails应用程序没有以www-data用户身份运行。为了测试目的,我将实际运行脚本的用户的ssh密钥添加到了我的Bitbucket存储库中,并且它起作用了。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接