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-
- Username- It is the name of the user using which you login into Linux system.
- Password- This field has a value x which means encrypted password of the user is stored in /etc/shadow file.
- 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.
- GID- Each user is a member of a primary group and this field stores the group ID of that group.
- 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.
- 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.
- 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
The above line shows login-related information for user meera and below it is explained in detail-
- Username is meera.
- Password is stored in /etc/shadow file.
- UID of user meera is 502.
- GID of user meera is 502.
- Meera Yadav is the full name of user meera.
- Home directory of this user is /home/meera.
- When meera login then /bin/bash shell will be launched.