Open In App

grpck command in Linux with Examples

grpck command in Linux System verifies the integrity of the groups information. It checks that all entries in /etc/group and /etc/gshadow have the proper format and contain valid data. The user is prompted to delete entries which are in incorrect formatted or which have uncorrectable errors. Syntax:

grpck [options] [group [gshadow]]

Description: Checks are made to verify that each entry has:

The checks for the correct number of fields and a unique group name are fatal. If an entry has the wrong number of fields, the user will be prompted to delete the entire line. The commands which operate on the /etc/group and /etc/gshadow files are not able to alter corrupted or duplicated entries. grpck should be used in those circumstances to remove the offending entries. Configuration: The following configuration variables in /etc/login.defs change the behavior of this tool:

Exit Values: The grpck command exits with the following values:

grpck command without any Option: It will give two message immediately

Example: We can’t use grpck command directly. Only the Administrator or root user can use this commands. Different options with the grpck Command: We can use grpck command when we are Administrator or root user. Use command given below to enter in root or administrator mode.

Sudo -i

Example: Now we will create Users and will apply grpck command to see how it will work. We can Create Group and User using this command.

addgroup group_name
adduser user_name -G group_name

addgroup: Use to create Group. adduser: Use to create User. We can create as many users we want instantly, Here I’m creating 100 users just by one command:

for i in `seq 1 100`; do echo adduser -G group1 "user$i"|| break ;done

Examples: User and Group Configuration Files: We are seeing some unknown things from starting like – /etc/passwd, /etc/shadow etc. Let’s see what are these unknown symbols signifies.

# tail -1 /etc/passwd 
# tail -1 /etc/shadow 
# tail -1 /etc/gshadow 
# tail -1 /etc/group 

Now we successfully stored user in-group and know about all configuration Files . Options: 1. -r –read-only Execute the grpck command in read-only mode. This causes all questions regarding changes to be answered no without user intervention.

grpck -r /etc/passwd 

Example: 2. -s –sort Sort entries in /etc/group /etc/gshadow by GID(Group ID).

grpck -s /etc/group 


Article Tags :