5

About user and groups administration I found in many tutorials that appear:

  • gpasswd - to add and delete users to a group
  • usermod/deluser - to add, modify and delete users of a group

What is not very clear is - When gpasswd would be mandatory over usermod/deluser and viceversa?

4 Answers 4

5

deluser is a command to delete an user altogether from the system, not to remove an user from group.

There is no moduser command, you probably meant usermod.

Both with usermod and gpasswd you can add/remove users to/from group. They are two different ways to achieve the same.

However, you cannot change the user's primary group with gpasswd. That can be done with usermod only. gpasswd manages only so called supplementary groups. You can view user's primary and supplementary groups with a command: id -a username. Sample output:

uid=1000(raj) gid=1000(raj) groups=1000(raj),4(adm),20(dialout),24(cdrom),27(sudo),30(dip),46(plugdev),120(lpadmin),131(lxd),132(sambashare)

The group listed as gid= is the user's primary group. groups= lists all groups the user belongs to (primary group is first, followed by supplementary groups).

There are also some things (not directly related to group membership) that each of those commands can do. With usermod you can modify other attributes of the user (like users' default shell or home directory), and with gpasswd you can set a group password, that allows users who are not members of the group to temporarily join the group if they know the password.

3
  • "not to remove an user from group" it can only delete a group ;)
    – Rinzwind
    Sep 28, 2021 at 7:50
  • 1
    "deluser is a command to delete an user altogether from the system, not to remove an user from group." - Sure it is: # deluser test adm -> Removing user `test' from group `adm' .... See also its documentation.
    – marcelm
    Sep 28, 2021 at 9:45
  • BTW usermod can't delete straightforward the secondary groups, but yes, is possible. Oct 1, 2021 at 13:28
4

It is never mandatory.

As with many tools different Linux systems merged lots of commnands so we have duplicate methods to do the same thing. There is also a delgroup and that one does a deluser --group.

deluser is part of a set of tools from Debian from the adduser package that Ubuntu inherited and it can delete only a group with the --group option. Other Linux will not have that and those will have to do with useradd.

Backwards compatibility is one reason, another was to get large groups of Unix users to start using Linux without the need to learn new commands. Or, as Linux is open, someone adding a feature used in Unix.

2

The commands you mention apply for different situations. You use them depending on what you want to accomplish.

The gpasswd command is used to administer /etc/group, and /etc/gshadow.

Meanwhile deluser:

remove a user or group from the system

As for usermod (not moduser):

modify a user account

0
  • gpasswd, groupmod: group Administrator, it is limited in managing the group only

  • usermod: root user, the command has far advanced authorization like changing group and user attributes

  • adduser, deluser, addgroup, delgroup, usermod: all of them can only be accessed by the root user and cannot be accessed by the group Administrator,as he might not have such authorization

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .