4.8. cloud-init を使用した sudoers の追加

sudo および groups エントリーを users セクションに追加することで、ユーザーを sudoer として設定できます。

手順

  1. データソースの要件に応じて、user-data ファイルを編集するか、以下のディレクティブを cloud.cfg.d ディレクトリーに追加します。

    注記

    cloud-init が、ユーザーディレクティブを含むファイルを認識できるように、すべてのユーザーディレクティブはファイルの最上部に #cloud-config が含まれます。cloud.cfg.d ディレクトリーにディレクティブを含める場合は、ファイル名を *.cfg とし、ファイルの最上部に常に #cloud-config を含めます。

  2. sudo エントリーを追加し、ユーザーアクセスを指定します。たとえば、sudo: ALL=(ALL) NOPASSWD:ALL は、ユーザーに無制限のユーザーアクセスを許可します。
  3. groups エントリーを追加し、ユーザーを含むグループを指定します。

    #cloud-config
    users:
      - default
      - name: user2
        gecos: User D. Two
        sudo: ["ALL=(ALL) NOPASSWD:ALL"]
        groups: wheel,adm,systemd-journal
        ssh_pwauth: True
        ssh_authorized_keys:
          - ssh-rsa AA...vz user@domain.com
    chpasswd:
      list: |
        root:password
        cloud-user:mypassword
        user2:mypassword2
      expire: False