Body: <p>I'm creating an Azure VM image using Packer. The VM is just a Debian 10 installation with a couple of packages installed.</p>
  
  <p>What I really need to do is to add VM admin user to a specific unix group (<code>docker</code>).</p>
  
  <p>During the packer image provisioning I make changes to the <code>/etc/adduser.conf</code> to enable extra groups:</p>
  
  <pre><code>  "provisioners": [{
      "execute_command": "chmod +x {{ .Path }}; {{ .Vars }} sudo -E sh '{{ .Path }}'",
      "inline": [
        "apt-get update",
        "apt-get upgrade -y",
        "apt-get -y install docker.io",
        "echo 'ADD_EXTRA_GROUPS=1\nEXTRA_GROUPS=\"docker\"' &gt;&gt; /etc/adduser.conf",
  
        "/usr/sbin/waagent -force -deprovision+user &amp;&amp; export HISTSIZE=0 &amp;&amp; sync"
      ],
      "inline_shebang": "/bin/sh -x",
      "type": "shell"
    }]
  </code></pre>
  
  <p>But it only adds explicitly created users to the <code>docker</code> group but the the admin users created with the following command:</p>
  
  <pre><code>az vm create \
      --resource-group myResourceGroup \
      --name myVM \
      --image myPackerImage \
      --admin-username azureuser \
      --generate-ssh-keys
  </code></pre>
  
  <p>Is there any way to add admin user to the group <code>docker</code> too?</p>
  
Comments: CC BY-SA 4.0
Comments: 2019-10-26T08:47:21.190Z
Comments: Maybe I misunderstand what you need, but I think you might need to look at `/etc/group` for that.
Comments: schaiba
Comments: CC BY-SA 4.0
Comments: 2019-10-27T05:58:14.813Z
Comments: If you just want to add a user to the docker group, perhaps you want usermod -Ga docker -l <username>
Comments: Bruce Becker
Comments: CC BY-SA 4.0
Comments: 2019-10-28T06:05:44.140Z
Comments: @BruceBecker the problem is that the `<username>` is unknown because it is all performed on the image provisioning stage.
Comments: Petr Razumov
Comments: CC BY-SA 4.0
Comments: 2019-10-30T17:03:09.813Z
Comments: From what I understand `waagent` doesn't actually use `adduser` hence why changes to `/etc/adduser.conf` doesn't work.
Comments: Richard Slater
Comments: CC BY-SA 4.0
Comments: 2019-11-14T18:22:22.413Z
Comments: @RichardSlater actually `waagent` uses `adduser`: https://github.com/Azure/WALinuxAgent/blob/3a3599b53121f5a2deb5761285657354610398fb/azurelinuxagent/common/osutil/default.py#L414
Comments: Petr Razumov
Comments: CC BY-SA 4.0
Comments: 2019-11-15T09:34:26.027Z
Comments: Actually that link shows it uses ‘useradd’, adduser is an abstraction over useradd, unfortunately its adduser that reads the adduser.conf.
Comments: Richard Slater
Tags: <azure><packer>
Title: How to add Azure VM's admin user to a specific unix group?
UserDisplayName: Petr Razumov
ThreadText: # How to add Azure VM's admin user to a specific unix group?
  
  (Asked by: username_0 on 2019-10-25)
  
  I'm creating an Azure VM image using Packer. The VM is just a Debian 10 installation with a couple of packages installed.
  
  What I really need to do is to add VM admin user to a specific unix group (`docker`).
  
  During the packer image provisioning I make changes to the `/etc/adduser.conf` to enable extra groups:
  
  ```
    "provisioners": [{
      "execute_command": "chmod +x {{ .Path }}; {{ .Vars }} sudo -E sh '{{ .Path }}'",
      "inline": [
        "apt-get update",
        "apt-get upgrade -y",
        "apt-get -y install docker.io",
        "echo 'ADD_EXTRA_GROUPS=1\nEXTRA_GROUPS=\"docker\"' >> /etc/adduser.conf",
  
        "/usr/sbin/waagent -force -deprovision+user && export HISTSIZE=0 && sync"
      ],
      "inline_shebang": "/bin/sh -x",
      "type": "shell"
    }]
  
  ```
  
  But it only adds explicitly created users to the `docker` group but the the admin users created with the following command:
  
  ```
  az vm create \
      --resource-group myResourceGroup \
      --name myVM \
      --image myPackerImage \
      --admin-username azureuser \
      --generate-ssh-keys
  
  ```
  
  Is there any way to add admin user to the group `docker` too?
  
  **Tags:** azure, packer
  
  > **Comments:**
  > **username_1**: Maybe I misunderstand what you need, but I think you might need to look at `/etc/group` for that.  
  > **username_2**: If you just want to add a user to the docker group, perhaps you want usermod -Ga docker -l <username>  
  > **username_0**: @username_2 the problem is that the `<username>` is unknown because it is all performed on the image provisioning stage.  
  > **username_3**: From what I understand `waagent` doesn't actually use `adduser` hence why changes to `/etc/adduser.conf` doesn't work.  
  > **username_0**: @username_3 actually `waagent` uses `adduser`: https://github.com/Azure/WALinuxAgent/blob/3a3599b53121f5a2deb5761285657354610398fb/azurelinuxagent/common/osutil/default.py#L414  
  > **username_3**: Actually that link shows it uses ‘useradd’, adduser is an abstraction over useradd, unfortunately its adduser that reads the adduser.conf.  
  
  ---
  
  ## 0 answers
  
  