Automatically add users to groups

Solution 1:

This can be achieved using the /etc/adduser.conf file in the following way. Edit the file:

sudo nano /etc/adduser.conf

In change these lines:

# Set this if you want the --add_extra_groups option to adduser to add
# new users to other groups.
# This is the list of groups that new non-system users will be added to
# Default:
#EXTRA_GROUPS="dialout cdrom floppy audio video plugdev users"

# If ADD_EXTRA_GROUPS is set to something non-zero, the EXTRA_GROUPS
# option above will be default behavior for adding new, non-system users
#ADD_EXTRA_GROUPS=1

To:

# Set this if you want the --add_extra_groups option to adduser to add
# new users to other groups.
# This is the list of groups that new non-system users will be added to
# Default:
EXTRA_GROUPS="audio"

# If ADD_EXTRA_GROUPS is set to something non-zero, the EXTRA_GROUPS
# option above will be default behavior for adding new, non-system users
ADD_EXTRA_GROUPS=1

Now whenever you use adduser the user will also be added to the audio group. Please note that that group must exist. SO first create the group if it doesn't exist then add it to the /etc/adduser.conf.

You can control this behaviour by setting

ADD_EXTRA_GROUPS=1

to

ADD_EXTRA_GROUPS=0

This will disable this behaviour, so one can always switch it on/off.