Linux /etc/passwd file

In Linux, all the login data of users are stored in /etc/passwd file. It is a simple text file that is used during login of a user. User information such as username, UID, GID, home directory, shell, etc. are stored in /etc/passwd file. This file is readable to all users but can only be modified by the root user.

In this file, there are seven fields per line and each field is separated by a colon(:). Each row in this file represents entry of one user. Below image is a sample entry from passwd file-

Linux passwd file
  1. Username- It is the name of the user using which you login into Linux system.
  2. Password- This field has a value x which means encrypted password of the user is stored in /etc/shadow file.
  3. UID- This field holds a User ID of the user. If a user is root then the value of UID is 0. UIDs below 500 are reserved for system accounts. The normal user is assigned UID from 500 onwards.
  4. GID- Each user is a member of a primary group and this field stores the group ID of that group.
  5. Comment- It is sometimes referred to as GECOS. It holds information about the user such as first and last name, email address, phone number, etc.
  6. Home Directory- Here, it holds the absolute path of user's home directory. For root, it is /root and for a normal user, it is /home/username.
  7. Login shell- The shell that is mentioned in this field will be launched when a login. In case, you set the value of this field to a shell that does not exist then the user will not able to log in. Here, you provide absolute path of the shell.

Note: /etc/passwd file does not store the actual password because it is world-readable.

Example entry of Linux /etc/passwd file

meera:x:502:502:Meera Yadav:/home/meera:/bin/bash

The above line shows login-related information for user meera and below it is explained in detail-

  1. Username is meera.
  2. Password is stored in /etc/shadow file.
  3. UID of user meera is 502.
  4. GID of user meera is 502.
  5. Meera Yadav is the full name of user meera.
  6. Home directory of this user is /home/meera.
  7. When meera login then /bin/bash shell will be launched.