ElasticBeanstalk - 将 ec2-user 添加到另一个组

Posted

技术标签:

【中文标题】ElasticBeanstalk - 将 ec2-user 添加到另一个组【英文标题】:ElasticBeanstalk - Adding ec2-user to another group 【发布时间】:2015-12-25 08:58:18 【问题描述】:

我有一个需要在我的 EC2 实例上以ec2-user 运行的 cron 作业,并且它需要能够写入我的 Web 应用程序的标准日志文件。但是,日志文件归webapp 所有(正常)。

我已成功更改日志文件的权限,以便所有者和组webapp:webapp 都可以访问它们。但是当我尝试将ec2-user 添加到webapp 组时,我遇到了麻烦。

我可以在 SSH 中使用 sudo usermod -a -G webapp ec2-user 很好地做到这一点,但是当我尝试通过 EB container-commands 添加此命令时,我收到一条错误消息,提示 you must have a tty to run sudo。运行不带 sudo 的命令会给我/bin/sh: usermod: command not found

任何人都知道能够通过 Elastic Beanstalk 部署配置将 ec2-user 添加到 webapp 组的任何其他方式。

【问题讨论】:

谢天谢地,你问我到底在找什么。请考虑接受正确答案 【参考方案1】:

不确定 sudoers 文件的问题,但通常将用户添加到组(比手动执行命令)更简洁的方法是使用 .ebextensions 文件的 users 部分。例如在.ebextensions/something.config:

users:
  ec2-user:
    groups:
      - webapp

【讨论】:

【参考方案2】:

你不应该使用 sudo,部署脚本是由 root 运行的。

另外,这是一个服务器命令,在命令部分而不是容器命令部分执行。

commands:
  01_set_user_role:
    command: "usermod -a -G webapp ec2-user"

【讨论】:

【参考方案3】:

You need to run this command from a container_command before executing any commands with sudo:

echo Defaults:root \!requiretty >> /etc/sudoers

在上下文中(在 .ebextensions/yourconf.config 中)

container_commands:
  001-enableroot:
    command: echo Defaults:root \!requiretty >> /etc/sudoers #disables error related to needing a tty for sudo, allows running without cli

【讨论】:

我不能确定这是否是一个答案,因为我需要这个的具体项目已经从我手中拿走了,但在阅读sudo.ws/man/1.8.13/… 的文档时,似乎很有可能.

以上是关于ElasticBeanstalk - 将 ec2-user 添加到另一个组的主要内容,如果未能解决你的问题,请参考以下文章

AWS EC2 和 Elastic Beanstalk

Django 频道 2 和 EC2 / Elasticbeanstalk

AWS ElasticBeanstalk EC2 终止保护

Websocket 适用于 EC2 url,但不适用于 ElasticBeanstalk URL

将 EC2 安全组限制为 Elastic Beanstalk 实例

访问 ElasticBeanstalk EC2 日志文件的更简单方法