簡體   English   中英

Capistrano和Bitbucket權限被拒絕

[英]Capistrano and Bitbucket permission denied

我正在嘗試使用我的Rails應用程序設置capistrano,並使用digitalocean進行托管。

我有一個運行unicorn和nginx的Ubuntu服務器。

我的capistrano部署在此階段一直失敗:

DEBUG [08cab5b3] Command: cd /home/rails/automata && (     GIT_ASKPASS=/bin/echo GIT_SSH=/tmp/automata/git-ssh.sh /usr/bin/env git     clone --mirror git@bitbucket.org:automata_tech/staging.git     /home/rails/automata/repo )
DEBUG [08cab5b3]        Cloning into bare repository     '/home/rails/automata/repo'...
DEBUG [08cab5b3]        /home/rails/automata/repo: Permission denied
(Backtrace restricted to imported tasks)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as     deployer@178.62.4.140: git exit status: 1
git stdout: Nothing written
git stderr: Cloning into bare repository    '/home/rails/automata/repo'...
/home/rails/automata/repo: Permission denied

SSHKit::Command::Failed: git exit status: 1
git stdout: Nothing written
git stderr: Cloning into bare repository    '/home/rails/automata/repo'...
/home/rails/automata/repo: Permission denied

Tasks: TOP => git:create_release => git:update => git:clone
(See full trace by running task with --trace)
The deploy has failed with an error: Exception while executing as     deployer@178.62.4.140: git exit status: 1
git stdout: Nothing written
git stderr: Cloning into bare repository    '/home/rails/automata/repo'...
/home/rails/automata/repo: Permission denied

我在服務器上生成了一個ssh密鑰,並將其添加到我的bitbucket帳戶中。

如果我使用ssh進入服務器並git克隆存儲庫,則可以正常工作。

在服務器上運行ssh -T git@bitbucket.org返回:

 logged in as company.

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

staging.rb:

set :ssh_options, {
  forward_agent: true,
  auth_methods: %w(publickey)
}

當您嘗試創建目錄/home/rails/automata/repo時,您的錯誤消息顯示permission denied錯誤。 換句話說,您的部署者用戶沒有必要的文件權限。 它與您的SSH密鑰或Bitbucket無關。

只需確保/home/rails/automata存在並且由deployer擁有。 您可能需要使用sudo或以root身份登錄才能執行此操作。

mkdir -p /home/rails/automata
chown deployer /home/rails/automata

順便說一句,我不確定將您的應用放在/home/rails有意義。 如果您使用deployer來部署應用程序(並因此成為應用程序的所有者),將其放在/home/deployer是否更有意義? 還是在“中立”位置(如/var/www/automata (如Capistrano的默認設置)?

在config / deploy / production.rb(或staging.rb)中,您需要啟用ssh代理轉發。

您可以通過將服務器文件更改為包括forward_agent: true

這是一個例子:

server 'xxx.xxx.xxx.xxx',
  user: 'deploy',
  roles: %w{web app db},
  ssh_options: {
    forward_agent: true,
    auth_methods: %w(publickey)
  }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM