【问题标题】:Capistrano and Bitbucket permission deniedCapistrano 和 Bitbucket 权限被拒绝
【发布时间】:2016-02-19 17:55:54
【问题描述】:

我正在尝试使用我的 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 clone 存储库,那就可以了。

在服务器上运行 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)
}

【问题讨论】:

    标签: ruby-on-rails capistrano digital-ocean


    【解决方案1】:

    尝试创建目录/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 默认建议)?

    【讨论】:

    • 谢谢,解决了将目录更改为 /home/deployer 的问题。
    【解决方案2】:

    在您的 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)
      }
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-08-24
    • 2023-03-22
    • 1970-01-01
    • 2018-03-11
    • 2014-01-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多