Difference between adduser and usermod -G -a

9,858

Solution 1

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 like useradd, groupadd and usermod programs.

More info:

  • man adduser : adduser, addgroup - add a user or group to the system
  • man usermod : usermod - modify a user account

Solution 2

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);
Share:
9,858
snoob dogg
Author by

snoob dogg

I do a bit of all, I like Max/MSP Jitter env, Python, Javascript, QB45

Updated on September 18, 2022

Comments

  • snoob dogg
    snoob dogg over 1 year

    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.

  • snoob dogg
    snoob dogg about 6 years
    ok so, the two commands I give do exactly the same thing ?
  • Terrance
    Terrance about 6 years
    @snoobdogg What is meant is that they are different. 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.
  • snoob dogg
    snoob dogg about 6 years
    ok I get it, but the two commands I give in my question do the same thing yes or no?
  • Yaron
    Yaron about 6 years
    @snoobdogg - you can add a user to a group using the two commands as you specify in your question. Those two commands differ in various other parameters.
  • Terrance
    Terrance about 6 years
    @snoobdogg Yes, they are the same commands. From the adduser man page: If called with two non-option arguments, adduser will add an existing user to an existing group.