简体   繁体   English

Capistrano和Bitbucket权限被拒绝

[英]Capistrano and Bitbucket permission denied

I'm trying to set up capistrano with my Rails app and hosting using digitalocean. 我正在尝试使用我的Rails应用程序设置capistrano,并使用digitalocean进行托管。

I have a Ubuntu server running unicorn and nginx. 我有一个运行unicorn和nginx的Ubuntu服务器。

My capistrano deploy keeps failing at this stage: 我的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

I have generated a ssh key on the server and added it to my bitbucket account. 我在服务器上生成了一个ssh密钥,并将其添加到我的bitbucket帐户中。

If I ssh into the server and git clone the repo, that works fine. 如果我使用ssh进入服务器并git克隆存储库,则可以正常工作。

Running ssh -T git@bitbucket.org on the server returns: 在服务器上运行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 : staging.rb:

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

Your error message shows a permission denied error when trying to create the directory /home/rails/automata/repo . 当您尝试创建目录/home/rails/automata/repo时,您的错误消息显示permission denied错误。 In other words, your deployer user doesn't have the necessary file permissions. 换句话说,您的部署者用户没有必要的文件权限。 It has nothing to do with your SSH key or Bitbucket. 它与您的SSH密钥或Bitbucket无关。

Just make sure that /home/rails/automata exists and is owned by deployer . 只需确保/home/rails/automata存在并且由deployer拥有。 You may need to use sudo or log in as root to do this. 您可能需要使用sudo或以root身份登录才能执行此操作。

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

BTW, I'm not sure placing your app inside /home/rails makes sense. 顺便说一句,我不确定将您的应用放在/home/rails有意义。 If you are using deployer to deploy (and thus be the owner of) your app, wouldn't it make more sense to put it in /home/deployer ? 如果您使用deployer来部署应用程序(并因此成为应用程序的所有者),将其放在/home/deployer是否更有意义? Or in a "neutral" location like /var/www/automata (as Capistrano suggests by default)? 还是在“中立”位置(如/var/www/automata (如Capistrano的默认设置)?

In your config/deploy/production.rb (or staging.rb), you need to enable ssh agent forwarding. 在config / deploy / production.rb(或staging.rb)中,您需要启用ssh代理转发。

You can do this by changing your server file to include forward_agent: true . 您可以通过将服务器文件更改为包括forward_agent: true

Here's an example: 这是一个例子:

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