Understanding /etc/group File

by nixcraft on February 25, 2006 · 16 comments

Can you explain me the format of /etc/group user group file under Linux / UNIX 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 (:)

cdrom:x:24:vivek,student13,raj
_____ _  _      _____
|    |  |        |
|    |  |        |
1    2  3        4

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
$ more /etc/group

Task: Find Out the Groups a User Is In

Type the following 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:

$ 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

Featured Articles:

Share this with other sys admins!
Facebook it - Tweet it - Print it -

{ 16 comments… read them below or add one }

1 Brian November 19, 2008

On the money. The detail was clear and straight forward. I quickly found the answer to the problem that we were facing in our production test environment.

Reply

2 Chakradana January 19, 2009

Clear and good.

Reply

3 null March 14, 2009

wonderful

Reply

4 miguel rodríguez March 19, 2009

perfect!! just what i need ;)

Reply

5 chris April 29, 2009

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 …

Reply

6 Ray V May 19, 2009

Will a blank line in the /etc/group file cause a system read problem? I know on some UNIX platforms, a blank line in the password file causes problems. Thanx

Reply

7 Vivek Gite May 19, 2009

It may cause a problem. It is better to remove a blank line. But I never tested it… YMMV.

Reply

8 Pete VargasMas October 20, 2009

Can a group be a member of another group?

Reply

9 rahul November 18, 2009

What is the default permission for /etc/group

Reply

10 Nethaji Reddy May 13, 2010

If I add my Group ID or Account name to admin/root in /etc/group, will it work. If not how can I do the same.

Reply

11 trusktr August 6, 2010

But why exactly do some in my group file have and x, or nothing at all in the password field? What’s the purpose?

Reply

12 vahid September 18, 2010

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 root@host to my nis group so when that machine comes up in initialization access those files and execute them?

Reply

13 eduard December 9, 2010

are there any commands that can show / list all members of a group (using hp-ux)? thanks

Reply

14 paul erickson December 23, 2010

Good, but did not mention what the ‘x’ means in the password.

Reply

15 michal December 15, 2011

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.

Reply

16 Ricardo October 14, 2011

Very good explanation!!

Reply

Leave a Comment

You can use these HTML tags and attributes for your code and commands: <strong> <em> <ol> <li> <u> <ul> <blockquote> <pre> <a href="" title="">
What is 15 + 2 ?
Please leave these two fields as-is:
IMPORTANT! To be able to proceed, you need to solve the simple math so we know that you are a human and not a script.




Previous post:

Next post: