Skip to content

Instantly share code, notes, and snippets.

@shantanoo-desai
Last active September 12, 2022 13:24
Show Gist options
  • Save shantanoo-desai/995484bdd9cec7d7221dddcba6e8107b to your computer and use it in GitHub Desktop.
Save shantanoo-desai/995484bdd9cec7d7221dddcba6e8107b to your computer and use it in GitHub Desktop.
Create `admin` user in cloud-init

Creating a user called admin using cloud-init

Cloud-Init may not create a user literally called admin even though the configuration might be valid.

Debugging

Log files are available:

cat /var/log/cloud/cloud-init.log
cat /var/log/cloud/cloud-init-output.log

Error

The error one receives from cloud-init module execution

useradd: group admin exists - if you want to add this user to that group, use -g.

Solution

It turns out that there already exists an admin group beforehand in GNU/Linux and cloud-init will generally also create a group according to <username>, in this case admin causing conflicts.

The solution is to let cloud-init know that it shouldn't create an additional group using no_user_group: true

#cloud-config
ssh_pwauth: true
preserve_hostname: false
hostname: mydevicename0
timezone: Europe/Berlin
users:
- name: admin
plain_text_passwd: mySuperAdminPassword
no_user_group: true # `admin` group already exists in GNU/Linux, don't insist on create another one
groups: sudo, adm
sudo: ALL=(ALL) NOPASSWD:ALL
shell: /bin/bash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment