6

Is it possible to add a user to a group without usermod? I'm working on embedded Linux 3.14.52 and I don't have the usermod command line. If it is not possible, how add this command to kernel with Buildroot?

M.Ferru
  • 400
  • 1
  • 6
  • 20

3 Answers3

2

The user<->group association is saved in the /etc/group file. Each line of the file is in the format:

group_name:password:GID:user_list

You can add users in the comma-separated user_list part. If you prefer to use some existing tool, you can consider gpasswd (if available).

I don't know how to help you for the kernel/buildroot question.

Andrea Carron
  • 1,001
  • 13
  • 22
2

In Buildroot, users and groups are created with the BR2_ROOTFS_USERS_TABLES configuration option. Set it to a file or list of files or users you want to create. See section 9.6 of the Buildroot manual. Note that this only allows you to specify users; groups are created automatically when a user is assigned to a group.

Alternatively, you can take control of the entire /etc/groups file by adding a filesystem overlay.

To update the group configuration at runtime, you can use the addgroup and delgroup utilities in busybox.

Arnout
  • 2,927
  • 16
  • 24
  • Thanks for your answer. So the option "BR2_ROOTFS_USERS_TABLES" works like the overlay? I give a "group" file and then it will be load in the kernel at start up? So there is no way to add or remove user from a group at runtime (but editing /etc/groups)? – M.Ferru Jun 27 '16 at 06:24
  • Read the manual or the help text of BR2_ROOTFS_USERS_TABLES: that option specifies a file in "mkusers syntax" which will be used to create additional users and groups. For runtime updates, I've added addgroup and delgroup to the answer. – Arnout Jun 27 '16 at 11:46
  • The `BR2_ROOTFS_USERS_TABLE` option does not work, sadly, at least not as described in the manual. According to the manual, a line like `user 1000 group 1000 - /home/user /bin/sh video` should work, but the user is not being created. You can easily see this, because no home directory and no entry in passwd is created. – Philipp Ludwig Apr 11 '23 at 07:07
  • It's hard to debug your issue without more information. The option is called `BR2_ROOTFS_USERS_TABLES`, with S, but I guess that's just a typo. You can check if your configuration is taken into account by looking at output/build/buildroot-fs/full_users_table.txt after the build - if it doesn't contain your user line, you did something wrong in the configuration. – Arnout Apr 14 '23 at 08:25
0

Also, you can create groups by assigning them to that user at first with -G option.

sudo useradd -G group1,group2 username1

You can check the user groups by typing

id username1

output :

uid=1000(username1) gid=1002(username1) groups=1002(username1),1000(group1),1001(group2)