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.