Difference between adduser and usermod -G -a
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
adduser
is friendlier front ends to the low level tools likeuseradd
,groupadd
andusermod
programs.
More info:
- man adduser :
adduser
,addgroup
- add a user or group to the system- man usermod :
usermod
- modify a user account
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);