Where is GECOS stored?

QuestionsQuestions8 SkillsProYour First Linux LabDec, 05 2025
0207

The GECOS field is stored in the /etc/passwd file on Unix-like operating systems, including Linux. This file contains user account information, with each line representing a different user account and structured in a specific format.

Structure of /etc/passwd

Each line in the /etc/passwd file has the following format:

username:password:UID:GID:GECOS:home_directory:shell
  • username: The user's login name.
  • password: An 'x' or '*' indicating that the password is stored in a shadow file for security.
  • UID: The user ID number.
  • GID: The group ID number.
  • GECOS: The full name of the user and possibly other information (like office number, phone number, etc.).
  • home_directory: The path to the user's home directory.
  • shell: The default shell for the user.

Example Entry

Here’s an example of a line from the /etc/passwd file:

labex:x:1001:1001:Lab Ex,,,:/home/labex:/bin/bash

In this example:

  • labex is the username.
  • x indicates that the password is stored securely.
  • 1001 is the UID and GID.
  • Lab Ex,,, is the GECOS field, which contains the user's full name.
  • /home/labex is the home directory.
  • /bin/bash is the default shell.

Accessing the GECOS Field

You can view the contents of the /etc/passwd file to see the GECOS field for all users:

cat /etc/passwd

To find the GECOS field for a specific user, you can use:

getent passwd username

Or:

grep username /etc/passwd

Summary

The GECOS field is stored in the /etc/passwd file, which contains essential information about user accounts on the system. If you have any more questions or need further clarification, feel free to ask!

0 Comments

no data
Be the first to share your comment!