I am using cloud-init to initialize a RHEL Atomic Host VM.

I have the following as my user-data file:

  - ourgroup
  - name: muser
    primary_group: ourgroup
    lock_passwd: false
      - ssh-rsa [REDACTED]
  - name: auser
    primary_group: ourgroup
    passwd: [REDACTED]
    lock_passwd: false
ssh_pwauth: True

When the VM boots up for the first time using an ISO file generated from that user-data file, the users are created. From what I see in /etc/passwd, the auser user is created with UID 1000, and the muser user is created with UID 1001.

We are deploying some software on this VM that needs to know the UID of muser in advance prior to installation. Whenever a VM is deployed using that ISO file, will muser always be created after auser (and therefore muser will always have UID 1001)?

I thought maybe the users were created in either alphabetical order or in the reverse order in which they are listed in the user-data file, so I created another user-data file with 4 users to test that theory. But that theory failed, and I could not tell in what order cloud-init creates the users.

If no one knows what order the users are created in, can I at least assume that muser will always have a UID of 1001?


It turns out there is a uid field as mentioned here, so I can use that to ensure that each user has a specific UID.

However, as mentioned here, there is a bug with how the uid field is parsed. Adding uid: 1001 did not work to set the User ID, but adding uid: "1001" worked.


Why does it matter? You can always get the UID at runtime with the id command, i.e.:

id -n muser

So you can modify your installation script to pick up the UID by running that command, for example:

uid=$(id -n muser)
echo "Installing mysoftware under UID $uid"
  • There is a Dockerfile used to create an image and it needs to know the UID. The machine the image is created on is not the same machine on which the software is eventually installed. – pacoverflow Oct 30 '18 at 4:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.