• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

groupmems Command Examples in Linux

by admin

A user is always a member of one group, the primary group, in the passwd database. Besides being a member of a primary group, additional group memberships can be added. This can be necessary to get access to a group directory/share or to delegate privileges in the sudo configuration. You can add existing additional groups with the –groups parameter of the useradd command during the creation of a user or afterward with usermod or groupmems.

Let’s create a new user and a new group and verify the results:

# useradd student
# passwd student
# groupadd staff

Make the user student a member of the group staff:

# groupmems -g staff -a student
# groupmems -g staff -l 

groupmems Commands Examples

1. To add a user to a group:

# groupmems -a mike -g SUPPORT
# groupmems --add mike -g SUPPORT 

2. To delete/remove a user from a group:

# groupmems -d mike SUPPORT -g SUPPORT
# groupmems --delete mike SUPPORT -g SUPPORT

3. To change the group name:

# groupmems -g SUPPORT

4. To remove the users from group:

# groupmems -p -g SUPPORT
# groupmems --purge -g SUPPORT

5. To list the members of the group:

# groupmems -l -g SUPPORT
# groupmems --list -g SUPPORT

Final Thought

Because a user’s group membership is defined in two different locations, it can be difficult to find out which groups exactly a user is a member of. A convenient command to check this is groupmems. Use, for example, the command groupmems -g sales -l to see which users are a member of the group sales. This shows users who are a member of this group as a secondary group assignment, but also users who are a member of this group as the primary group assignment.

Filed Under: Linux

Some more articles you might also be interested in …

  1. CentOS / RHEL : How to install and start the Apache httpd service
  2. How to Replace a Failed Btrfs Device
  3. How to Manage Zimbra Account Status from CLI
  4. How To Disable MD5-based HMAC Algorithm’s for SSH
  5. SSHFS (Secure SHell FileSystem) – Securely Mount remote filesystem over ssh
  6. How to schedule Jobs with Cron in Linux
  7. CentOS / RHEL : How to find Logical volumes (LVs) contained in Physical Volume (PVs) in LVM
  8. egrep Command Examples in Linux
  9. How to Configure ACL(Access Control Lists) in Linux FileSystem
  10. Anonymous User Fails to Upload File to VSFTP Server

You May Also Like

Primary Sidebar

Recent Posts

  • grpck command – Remove corrupt or duplicate entries in the /etc/group and /etc/gshadow files.
  • xxd command – Expressed in hexadecimal form
  • sesearch: command not found
  • macof: command not found

© 2022 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright