Live as if you were to die tomorrow. Learn as if you were to live forever.

Wednesday, 18 February 2015

Information about /etc/group file in Linux/Unix


The /etc/group file contains the list of group along with the users associated with the group.


The /etc/group file contains group, group id, x which means password is stored in /etc/gshadow file and list of the users associated with the group.


The /etc/group file contains the information as shown below


[root@red /]# cat /etc/group

root:x:0:root

bin:x:1:root,bin,daemon

daemon:x:2:root,bin,daemon

sys:x:3:root,bin,adm

adm:x:4:root,adm,daemon

disk:x:6:root

wheel:x:10:root

mail:x:12:mail,postfix

test:x:500:

dnyaneshwar:x:501:

pramod:x:502:dnyaneshwar,test


This file contains four fields separated by colon (:)


1st field:    It contains the group name

2nd field:  It shows x which means password is stored in encrypted format in /etc/gshadow file

3rd field:  It contains the group id

4th field:  It contains the list of the users in the group.


If you see the below example:


pramod:x:502:dnyaneshwar,test


Here, pramod is the group name, x means password of group pramod is stored in /etc/gshadow file, 502 is the group id and dnyaneshwar, test are the users in the group.


Whenever you create the user it will automatically crate the group for that user.


How to add new user to the group?


To add new user to the group you can use usermod command.

#usermod -G group_name users


For e.g.

#usermod -G pramod vinod


Output

pramod:x:502:dnyaneshwar,test,vinod


Here, we have added the user vinod in group pramod


How to remove the user from group ?


We can use gpasswd command to remove the user from the group

#gpasswd –d username groupname


For e.g.

#gpasswd –d test pramod

Removing user test from group pramod



How the change check the primay group of the user and change it?


The primary group for any user is the username itself.

If you have created the user pramod then primary group for user pramod is the pramod itself.


Use the below command to check the primary group of the user


# groups pramod

pramod : pramod



To change primary group use the below command

# usermod -g test pramod

# groups pramod

pramod : test



Note: G is used to change the secondary group and g is used to change the primary group


Guys, Please add comment if you have any query or feedback.... :)

2 comments: