What is the difference between
adduser user_name group_name
and
usermod -G -a user_name group_name
At first glance they seems to do the same thing : add a user to a group.
What is the difference between
adduser user_name group_name
and
usermod -G -a user_name group_name
At first glance they seems to do the same thing : add a user to a group.
adduser and usermod are two different utilities which have in common the fact that both can add a user to a group.
According to man adduser
adduseris friendlier front ends to the low level tools likeuseradd,groupaddandusermodprograms.
More info:
- man adduser :
adduser,addgroup- add a user or group to the system- man usermod :
usermod- modify a user account
usermod cannot add a user to the system like adduser can. They just happen to share the ability to add a user to a group.
– Terrance
Mar 04 '18 at 15:14
adduser man page: If called with two non-option arguments, adduser will add an existing user to an existing group.
– Terrance
Mar 04 '18 at 15:20
At first glance, yes.
At second glance, usermod -G -a user_name group_name is not correct.
The -G option should be followed by the group name(s).
$ sudo usermod -G -a nogroup muru
[sudo] password for muru:
usermod: group '-a' does not exist
$ sudo usermod -a -G muru nogroup
usermod: user 'nogroup' does not exist
The -a can come before -G, or after the group name(s), but not between -G and the group name(s).
As a side note, adduser itself uses gpasswd:
$ grep gpasswd $(which adduser)
my $gpasswd = &which('gpasswd');
&systemcall($gpasswd, '-a',$existing_user,$existing_group);
usermod -G -a user_name group_namewould be wrong either way. I think you'd wantusermod -G group_name -a user_nameorusermod -a -G group_name user_nameinstead. – Mismatch Apr 24 '23 at 14:21