Creating user groups

Sometimes, you might have to create user groups for successful installation of certain software. Also, having different user groups, with different privileges is a great way to control user permissions for directories.

Create a new user group and add users to it

  1. Log in to your system as the root user:

    localhost$ ssh root@<remote_ip>
  2. Use the groupadd command to add a new user group to your system:

    # groupadd newgroup
  3. Use the usermod command to add an user to the group:

    # usermod -aG newgroup existingUser
  4. You can add an user to multiple groups:

    # usermod -aG newgroup,group1,group2 existingUser
  5. You can check which users are in a group using the grep command:

    # grep newgroup /etc/group

    Or, you can do the same in a more elegant way, using the getent command:

    # getent group newgroup

Other articles:

How to list all users in Linux - part 1

How to create users in Linux

How to delete users in Linux

How to delete user groups in Linux