我在過去爲其他項目做了幾次這樣的事情,並最終讓它工作,但每次我似乎都無法完全記得該怎麼做。橡膠capistrano從bitbucket部署到ec2獲取權限被拒絕
我有一臺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
這工作得很好:
[email protected]:~$ ssh -T [email protected]
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 [email protected]: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
這裏是我的部署。 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, "[email protected]: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
啊,我認爲你正在做點什麼。用戶部署是root用戶,並且我爲用戶'ubuntu'獲取了ssh密鑰。我添加了root ssh密鑰(通過登錄到[email protected]並執行ssh-keygen,然後將id_rsa.pub添加到我的項目的部署密鑰中,然後添加到bitbucket中),現在它可以工作!祝賀它。 – Danny 2013-02-16 00:31:56