In Linux, when a user is created (it can be done using ‘useradd’ command), it will update some system files such as /etc/passwd, /etc/shadow and /etc/group. In this article, we will go through the file /etc/passwd which is one of the most important file in Linux. This file contains the essential information for a user to login to the Linux machine. This file can be read by any users but is writable only by the super user-root.
Each system user has a specific line in the /etc/passwd file which describes the username, UID, GID etc.
Each line has the following syntax.
As you can see, there are seven fields separated by a “colon :”. Now, we can see what each field represents.
This field defines the username of the user to login. Only local users have entries in passwd file. It should be between 1 to 32 characters.
2. Password (x)
The character “x” in this field represents that the encrypted password is available in /etc/shadow file. The password file doesn’t include the password for security reasons (readable by everybody). The /etc/shadow file is readable only by the root user. If you put * inplace of x then user can't login. If you keep second field blank then user can login without password.
Every user created in a Linux machine will have a unique user ID. The UID digit “0” represents “root” and UID 1 to 99 are reserved for other predefined accounts.
When a user is created using the command “useradd”, it will also create a primary group for the user in the same name as the “username” (if you didn’t explicitly mention any group name. The field GID represents the unique ID given for the primary group to which the user belongs to. A single user can be a member of multiple groups which can be found from the file “/etc/group”. But, the passwd file will contain the information of the primary group only.
5. User ID Info
This is used as an informational / comment field. It allows you to add extra information about the users such as user’s full name.
6. Home Directory
It represents the absolute path to the user's home directory. If this directory does not exist the '/' directory becomes the users home directory.
The absolute path of command or shell (/bin/bash). Typically this field contain information about user's default shell.
The default permission of the /etc/passwd file is 644, so that any user can read the information from /etc/passwd file.
-rw-r--r-- 1 root root 2659 Sep 10 12:25 /etc/passwd