自动将用户添加到群组中

我正在为一个朋友创建一个定制的ISO文件。
我如何将所有用户和未来的新用户添加到音频(或任何其他)组中?
如果我想添加单个用户,我会运行以下命令:
sudo adduser $USER audio

每次创建新用户账户时,是否有自动执行的方法?

4如果使用adduser添加用户,那么默认的/etc/adduser.conf不是已经这样做了吗?(通过EXTRA_GROUPSADD_EXTRA_GROUPS条目) - steeldriver
1个回答

这可以通过以下方式使用/etc/adduser.conf文件来实现。编辑该文件:
sudo nano /etc/adduser.conf

在更改这些行:
# 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

致:
# 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

现在每当您使用adduser命令时,用户也将被添加到音频组中。请注意,该组必须存在。因此,如果该组不存在,请先创建该组,然后将其添加到/etc/adduser.conf文件中。
您可以通过设置来控制此行为。
ADD_EXTRA_GROUPS=1

ADD_EXTRA_GROUPS=0

这将禁用此行为,以便用户始终可以切换它的开/关状态。