如何使用usermod将组添加到用户而不删除suse linux中的其他组?

joy*_*y87 7 group accounts

我有一个用户,其中有一个主要组和一个次要组,例如:

[ testuser Welcome ~ ]$ id

uid=2000(testuser) gid=2000(testuser) groups=2000(testuser),27(sudo),2001(testgroup)
Run Code Online (Sandbox Code Playgroud)

主要组是testuser& 次要组是testgroup

现在,我尝试使用以下命令向该用户再添加一个辅助组 testgroup2

usermod -G testgroup2 testuser
Run Code Online (Sandbox Code Playgroud)

但它删除了之前的次要组 ( testgroup) 并添加了新的组。我的需要是不应删除以前的次要组,而应添加新的次要组。

我在 ubuntu 中看到,有一个选项-a可以将组附加到用户而不删除其他组。

请让我知道是否也可以在 suse linux 上使用...?

谢谢!!!!

ctr*_*lor 1

此命令使您指定所有组的列表,它会替换旧的组。

 -G, --groups GROUP1[,GROUP2,...[,GROUPN]]]
           A list of supplementary groups which the user is also a member of. Each group is separated from the next by a comma, with no intervening whitespace. The groups are subject to the same restrictions as the group given with the -g option.
Run Code Online (Sandbox Code Playgroud)

而是使用adduser

adduser [options] user group
Run Code Online (Sandbox Code Playgroud)

adduser可以用来添加用户,也可以将用户添加到组中。


或者正如 @markplotnick 指出的那样,使用-a以下选项usermod