Understanding /etc/group File

Posted on in Categories , , , , , , , , last updated August 2, 2017

Can you explain me the format of /etc/group user group file under Linux / UNIX-like operating systems?

/etc/group is a text file which defines the groups to which users belong under Linux and UNIX operating system. Under Unix / Linux multiple users can be categorized into groups. Unix file system permissions are organized into three classes, user, group, and others. The use of groups allows additional abilities to be delegated in an organized fashion, such as access to disks, printers, and other peripherals. This method, amongst others, also enables the Superuser to delegate some administrative tasks to normal users.

/etc/group file

It stores group information or defines the user groups i.e. it defines the groups to which users belong. There is one entry per line, and each line has the following format (all fields are separated by a colon (:)

Fig.01: Sample entry in /etc/group file
Fig.01: Sample entry in /etc/group file

Where,

  1. group_name: It is the name of group. If you run ls -l command, you will see this name printed in the group field.
  2. Password: Generally password is not used, hence it is empty/blank. It can store encrypted password. This is useful to implement privileged groups.
  3. Group ID (GID): Each user must be assigned a group ID. You can see this number in your /etc/passwd file.
  4. Group List: It is a list of user names of users who are members of the group. The user names, must be separated by commas.

More About User Groups

Users on Linux and UNIX systems are assigned to one or more groups for the following reasons:

  • To share files or other resource with a small number of users
  • Ease of user management
  • Ease of user monitoring
  • Group membership is perfect solution for large Linux (UNIX) installation.
  • Group membership gives you or your user special access to files and directories or devices which are permitted to that group


(Fig.01: Understanding groups)

User tom is part of both ‘Web developers’ and ‘Sales’ group. So tom can access files belongs to both groups.

Task: View Current Groups Settings

Type any one of the following command:
$ less /etc/group
OR use the more command:
$ more /etc/group
OR use the cat command:
$ more /etc/group

Task: Find Out the Groups a User Is In

Type the following groups command:
$ groups {username}
$ groups
$ groups vivek

Sample outputs:

vivek : vivek adm dialout cdrom plugdev lpadmin netdev admin sambashare libvirtd

Task: Print user / group Identity

Use the id command to display information about the given user.

Display only the group ID, enter:

Use the id command:
$ id -g
$ id -g user
$ id -g vivek

OR
$ id -gn vivek

Display only the group ID and the supplementary groups, enter:

$ id -G
$ id -G user
$ id -G vivek

OR
$ id -Gn vivek

This entry is 3 of 3 in the Linux / UNIX System's Accounts Files Tutorial series. Keep reading the rest of the series:
  1. Understanding /etc/passwd File Format
  2. Understanding /etc/shadow file
  3. Understanding /etc/group file

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin and a trainer for the Linux operating system/Unix shell scripting. He has worked with global clients and in various industries, including IT, education, defense and space research, and the nonprofit sector. Follow him on Twitter, Facebook, Google+.

Share this on (or read 27 comments/add one below):

27 comment

  1. Great, Thanks!
    But one more question remains:
    Does /etc/group allow wildcards (probably not) or is it possible to allow all group members of one group to be part of another?
    I have the problem, that different linux installations (which are all needed unfortunately) provide different groups and user authentification is central from NIS …

  2. how can i allow the root user of another machine to view the files that are only set to be viewed by the users that are in /etc/group which is set on another machine?
    for example can we just add [email protected] to my nis group so when that machine comes up in initialization access those files and execute them?

    1. The ‘x’ means that password is stored in /etc/gshadow, not in /etc/group.. It’s the same way as in /etc/passwd, if you gave x in password field, it means that the user’s password is stored in /etc/shadow.

  3. Can I ask a very simple question? Usually, the owner of a file is also a member of the group which has ‘special’ access as defined by the permissions. If the owner is not a member of the group, can this lead to any difficulties? I do not think that their would be any problems, but I have never seen this written explicitly anywhere.

    Anyone know the answer?

    Barry

    1. Instead of two lines in your example, why not just do this?

      wheel:x:10:root,john,mike

      I was looking at this thread to see if something like crossing user permissions was okay. For example, this makes each user a member of the other user. Helpful for managing a media center from a different account.

      media:x:1000:don
      don:x:1001:media

Leave a Comment