Score:1

When gpasswd vs usermod/deluser?

kz flag

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?

Score:4
cn flag
raj

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.

cn flag
"not to remove an user from group" it can only delete a group ;)
marcelm avatar
cn flag
_"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](https://nixdoc.net/man-pages/Linux/man8/deluser.8.html#Remove%20an%20user%20from%20a%20specific%20group).
Manuel Jordan avatar
kz flag
BTW `usermod` can't delete straightforward the secondary groups, but yes, is possible.
Score:3
cn flag

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.

Score:2
au flag

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

Score:0
kz flag
  • 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

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.