自动将用户添加到组

Gio*_*ris 4 users groups

我正在为朋友创建自定义iso。

如何将所有用户和未来的新用户添加到音频(或任何其他)组?

如果我想添加一个用户,我会运行

sudo adduser $USER audio
Run Code Online (Sandbox Code Playgroud)

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

Geo*_*sen 6

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

sudo nano /etc/adduser.conf
Run Code Online (Sandbox Code Playgroud)

在更改这些行:

# 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
Run Code Online (Sandbox Code Playgroud)

到:

# 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
Run Code Online (Sandbox Code Playgroud)

现在每当您使用adduser该用户时,该用户也将被添加到音频组中。请注意,该组必须存在。因此,如果该组不存在,请先创建该组,然后将其添加到/etc/adduser.conf.

您可以通过设置来控制此行为

ADD_EXTRA_GROUPS=1
Run Code Online (Sandbox Code Playgroud)

ADD_EXTRA_GROUPS=0
Run Code Online (Sandbox Code Playgroud)

这将禁用此行为,因此您可以随时切换它on/off