How to add, remove and list user groups

Quick and useful commands in cases when you want to add/remove a user to a specific group and list all of the groups that certain user is added to.

Let’s first start with listing:

root@cb:~$ groups user
user : user sysadmins

Now when we know in which groups is the user added, we can proceed with adding it to some more:

root@cb:~# usermod -a -G sudo user

  • -G stands for the new list of additional groups
  • -a stands for Append, which means that the group mentioned by the -G option will be appended to the other groups, in which our user is member

And when we list the user’s groups again:

root@cb:~$ groups user
user : user sudo sysadmins

Perfect, if you want to remove the user from certain group, you can do the following:

root@cb:~$ gpasswd -d user sysadmins

root@cb:~$ groups user
user : user sudo