1

我过去曾为其他项目做过几次,并最终让它发挥作用,但每次我似乎都不记得到底该做什么。

我有一个 ec2 ubuntu 服务器,正在使用 capistrano 进行部署,并使用橡胶来设置 evertyhing。

在我的 ec2 服务器上,我生成了 ssh 密钥,添加到 bitbucket(在我的帐户下,ssh 密钥。起初我尝试在项目和部署密钥下,但这也不起作用)。在我的 ec2 服务器上,我可以成功手动 ssh 并直接将我的 repo 克隆到我的家中。我已将密钥添加到 ssh 代理。

如果我不使用 scm 并将 deploy_via 设置为 :copy,我可以很好地部署。我相信这会抓住我的本地项目并进行部署。

我读过这些:https ://confluence.atlassian.com/display/BITBUCKET/Using+Deployment+Keys https://confluence.atlassian.com/display/BITBUCKET/Troubleshooting+SSH+Issues https://confluence。 atlassian.com/pages/viewpage.action?pageId=270827678

这工作正常:

ubuntu@production:~$ ssh -T hg@bitbucket.org
conq: logged in as myBitBucketUser.

You can use git or hg to connect to Bitbucket. Shell access is disabled.

这是我在部署期间收到的错误消息:

* executing "if [ -d /mnt/myProject-production/shared/cached-copy ]; then cd /mnt/myProject-production/shared/cached-copy && git fetch -q origin && git fetch --tags -q origin && git reset -q --hard f2b5b8b6cd1c7835d020d66fdc09b42b2870561e && git clean -q -d -x -f; else git clone -q git@bitbucket.org:myRepo.git /mnt/myProject-production/shared/cached-copy && cd /mnt/myProject-production/shared/cached-copy && git checkout -q -b deploy f2b5b8b6cd1c7835d020d66fdc09b42b2870561e; fi"
    servers: ["production.myserver.com"]
    [production.myserver.com] executing command
 ** [production.myserver.com :: out] Permission denied (publickey).
 ** fatal: The remote end hung up unexpectedly

这是我的 deploy.rb:

set :rails_env, Rubber.env

on :load do
  set :application, rubber_env.app_name
  set :runner,      rubber_env.app_user
  set :deploy_to,   "/mnt/#{application}-#{Rubber.env}"
  set :copy_exclude, [".git/*", ".bundle/*", "log/*", ".rvmrc"]
end

# Use a simple directory tree copy here to make demo easier.
# You probably want to use your own repository for a real app
#set :scm, :none
#set :repository, "."
#set :deploy_via, :copy

ssh_options[:forward_agent] = true # also tried false
set :repository, "git@bitbucket.org:myProject.git"
set :scm, "git"
set :deploy_via, :remote_cache
set :branch, 'master'

# Easier to do system level config as root - probably should do it through
# sudo in the future.  We use ssh keys for access, so no passwd needed
set :user, 'root'
set :password, nil

# Use sudo with user rails for cap deploy:[stop|start|restart]
# This way exposed services (mongrel) aren't running as a privileged user
set :use_sudo, false # also tried true
4

2 回答 2

1

我将本地机器中生成的 ssh 密钥用于服务器和 bitbucket 存储库,并使用 capistrano 进行部署。因此,使用它可以解决您的问题。

我做的方式

我将本地机器的公钥(id_rsa.pub)用于

部署.rb

ssh_options[:forward_agent] = true

当部署服务器尝试连接到您的 git 服务器时,它将从您的本地计算机转发身份验证。

您尝试的方式的可能解决方案

与 ssh git@github.com 不同,ssh git@bitbucket 不会将自身添加到已知主机列表中。所以在bitbucket中做的方式一定是https://confluence.atlassian.com/display/BITBUCKET/Using+the+SSH+protocol+with+Bitbucket

于 2013-02-13T18:05:43.247 回答
0

我也使用橡胶遇到了这个问题。

如果您有多个实例,则需要为所有实例获取 SSH 密钥,因为 Rubber 会将代码部署到所有实例。还没有找到防止这种情况的方法。

要使用的 ssh 密钥在 ~/.ssh 或 /root/.ssh 下,如果您生成的密钥位于不同的目录或不同的用户下,它们可能不会被识别为使用用户“root”的橡胶部署,那就是从 repo 中获取的用户。

希望这可以帮助。

于 2013-02-15T01:10:08.740 回答