The /etc/passwd file in Linux explained


Today in this article we will explain /etc/passwd file format on Linux or Unix operating system.

What is /etc/passwd file in Linux

The /etc/passwd is a plain text file that stores essential information of all user accounts of a system. It contains information like user id, group id, home directory, etc. This file can be modified using command-line tools like usermod, useradd with root user permission. Many command-line utilities use this file to map user ids to user names.

How to display the content of /etc/passwd

You can use command-line tools like cat, less, or more to display the content of this file. Each line in the file contains a single user with some other information. Now use –

cat /etc/passwd

OR use one of the given commands to scroll and read the content –

less /etc/passwd

OR

more /etc/passwd

You can see the output in the given image –

Understanding the fields in /etc/passwd file

Each line in the file contains seven colon-separated fields. For example, the first line shows the root user information which has the given fields.

root:x:0:0:root:/root:/bin/bash

From left to right the information shows –

Username – It is used while user login. It should be between 1 to 32 characters in length. In the above example root is the username.

Encrypted password – It is indicated using character ‘x’  and stored in /etc/shadow file. This can be modified using the passwd command.

User ID (UID) – UID is a number assigned to each user in a Linux or Unix system. The system identifies a user with its UID and uses it to determine which system resources a user can access. User id 0 is reserved for the root user.

Group ID (GID) – The next field shows the primary group id of a user.

Full name of the user – This field can contains the comma-separated full user name, phone number, and such other information.

User’s home directory – This shows the absolute path to the user’s home directory. By default, it is created with the name of the user under the /home directory.

Default login shell – The absolute path to the default user’s login shell. By default, it is /bin/bashfor most of the Linux distribution. This can be changed later.

Conclusion

I hope you have a basic understanding of /etc/passwd file in Linux. In case you have a query then write us in the comments below.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.