【问题标题】:What user does cloud-config run as?cloud-config 以什么用户身份运行?
【发布时间】:2017-11-17 01:11:17
【问题描述】:

在启动 AWS 或其他云供应商实例并使用 cloud-init 配置主机时,被调用的 bash 脚本以什么用户身份运行?

【问题讨论】:

    标签: cloud-init


    【解决方案1】:

    使用以下配置构建实例:

    #cloud-config
    write_files:
      - path: /root/test.sh
        content: |
            #!/bin/bash
            set -x
            set -e
            whoami
    runcmd:
      - bash /root/test.sh
    

    我得到了一个输出:

    + whoami
    root
    

    Ubuntu cloud-config 以 root 身份运行。

    【讨论】:

    • 是否可以设置自定义用户?
    • @RovshanMusayev runuser -l $USER -c "
    • 在我看来这像是一个 hack,但不是原生的 cloud-init 功能。我不仅要运行命令,还要运行整个云初始化,包括使用自定义用户编写文件
    • 我不确定这是否可能。但是,如果有可能并且有人知道怎么做,我很乐意学习。
    • @RovshanMusayev 就文件而言,您可以以 root 用户身份编写这些文件,然后chown 将它们发送给您需要的任何用户。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-03-07
    • 2018-12-23
    • 2013-07-18
    • 1970-01-01
    • 2021-12-16
    • 2011-10-03
    • 2017-04-07
    相关资源
    最近更新 更多