【问题标题】:Deploying Rails App on AWS EC2 with Capistrano使用 Capistrano 在 AWS EC2 上部署 Rails 应用程序
【发布时间】:2013-03-12 20:09:15
【问题描述】:

我正在尝试在 AWS-EC2 实例上使用 Capistrano 部署 Rails 应用程序,默认用户 (Ubuntu) 在另一个用户的家中,但它给了我“权限被拒绝”错误。这是我的代码:

server "9.9.9.9", :web, :app, :db, primary: true

set :application, "some_app"
set :user, "ubuntu"
set :keep_releases, 3
set :location, "9.9.9.9"
ssh_options[:keys] = ["~/Keys/serverkey.pem"]
ssh_options[:forward_agent] = true
default_run_options[:pty] = true
set :use_sudo, false

task :hello do
  run "echo 'Hello World' > /home/other_user/i_was_here.txt"
end

这是输出:

$ cap hello
  * 2013-03-22 14:11:29 executing `hello'
  * executing "echo 'Hello World' > /home/other_user/i_was_here.txt"
    servers: ["9.9.9.9"]
    [9.9.9.9] executing command
 ** [out :: 9.9.9.9] sh: cannot create /home/other_user/i_was_here.txt: Permission denied
    command finished in 798ms
failed: "sh -c 'echo '\\''Hello World'\\'' > /home/other_user/i_was_here.txt'" on 9.9.9.9

可能出了什么问题?目的是为另一个用户部署一个 Rails 应用程序,所以我有一些疑问:

  1. 有没有办法让其他用户直接在 AWS-EC2 实例上部署 Rails 应用程序?
  2. 如果 #1 的答案是“否”,那么使用默认用户 Ubuntu 为其他用户部署 Rails 应用程序的正确方法是什么? (为了以后其他用户尝试访问应用程序时不会出现权限问题)

在服务器中管理着许多用户,因为我们想为每个用户获取存储和带宽,所以我们这样做了,直到今天我们从 Capistrano 开始哈哈。

提前致谢。

【问题讨论】:

    标签: ruby-on-rails deployment amazon-ec2 capistrano


    【解决方案1】:

    通常是作为应该运行/维护应用程序的用户进行部署。否则,您必须真正确保两个用户都没有弄乱权限。

    这种情况的原因是您不想共享凭据吗?如果是这样,请考虑为每个用户使用添加到 .ssh/authorized_keys 的特殊部署 ssh 密钥。

    【讨论】:

      【解决方案2】:

      从您的配置文件中删除 ssh_options[:forward_agent] = true 行,即使我有同样的问题,我删除了这行并且它现在对我来说工作正常

      【讨论】:

        【解决方案3】:

        谢谢大家的回答。我所做的就是按照这些步骤与特定用户联系 Capistrano。

        http://utkarshsengar.com/2011/01/manage-multiple-accounts-on-1-amazon-ec2-instance/

        【讨论】:

          【解决方案4】:

          ubuntu 用户没有权限访问 other_user 的主目录,除非使用了 sudo,或者你更改了 /home/other_user 的权限。

          如果您想以 other_user 身份运行应用程序,最好的方法是将 capistrano 配置为以 other_user 身份部署。您需要将公共 ssh 密钥添加到 /home/other_user/.ssh/authorized_keys。如果您希望应用程序作为 ubuntu 运行,请部署到 /home/ubuntu。

          【讨论】:

            猜你喜欢
            • 2013-09-29
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2016-02-27
            • 2014-05-21
            • 2017-06-12
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多