Detailed parsing of Linux/etc/passwd files

Source: Internet
Author: User

In the Linux/etc/passwd file, each user has a corresponding record line, which records some basic attributes of this user. System Administrators often access the modification of this file to manage users. This file is readable to all users. But what does the Linux/etc/passwd file contain?

Its content is similar to the following example:
# Cat/etc/passwd
Root: x: 0: 0: Superuser :/:
Daemon: x: 1: 1: Systemdaemons:/etc:
Bin: x: 2: 2: Ownerofsystemcommands:/bin:
Sys: x: 3: 3: Ownerofsystemfiles:/usr/sys:
Adm: x: 4: 4: Systemaccounting:/usr/adm:
Uucp: x: 5: 5: UUCPadministrator:/usr/lib/uuucp:
Auth: x: 7: 21: Authenticationadministrator:/tcb/files/auth:
Cron: x: 9: 16: Crondaemon:/usr/spool/cron:
Listen: x: 37: 4: Networkdaemon:/usr/net/nls:
Lp: x: 71: 18: Printeradministrator:/usr/spool/lp:
Sam: x: 200: 50: Samsan:/usr/sam:/bin/sh
From the above example, we can see that a row of records in/etc/passwd corresponds to a user, and each row of records is separated by a colon (:) into seven fields. Its format and meaning are as follows:
User name: Password: User ID: Group ID: annotation Description: main directory: logon Shell
"User Name" is a string representing the user account. Generally, it cannot exceed 8 characters and may consist of uppercase/lowercase letters and/or numbers. The login name cannot contain a colon (:), because the colon is a separator here. For the sake of compatibility, it is recommended that the login name do not contain periods (.), and do not use hyphens (-) or plus signs (+) to start.
In some systems, encrypted user passwords are stored. Although this field only stores the encrypted string of the user's password, it is still a security risk because the/etc/passwd file can be read by all users. Therefore, many Linux systems such as SVR4 now use the shadow technology to store the encrypted user password in the/etc/shadow file, in the/etc/passwd file, only one special character is stored in the password field, for example, "x" or "*".
The "User ID" is an integer used internally to identify users. Generally, it corresponds to the user name one by one. If several user names correspond to the same user ID, the system regards them as the same user, but they can have different passwords, different home directories, and different logon shells.
Generally, the user ID number ranges from 0 ~ 65535. 0 is the identification number of the Super User root, 1 ~ 99 is retained by the system and used as the management account. The identification number of a common user starts from 100. In Linux, this limit is 500.
The "group ID number" field records the user's user group. It corresponds to a record in the/etc/group file.
The "annotation description" field records the user's personal information, such as the real name, phone number, and address of the user. This field has no practical purpose. In different Linux systems, the format of this field is not uniform. In many Linux systems, this field stores any comments of the description text and is used as the output of the finger command.
"Main directory", that is, the user's initial working directory, which is the directory where the user logs on to the system. In most systems, the main directories of users are organized in the same specific directory, and the name of the main directories is the user's login name. Each user has the read, write, and execute search permissions on his/her home directory. Other users have the permission to access this directory based on the actual situation.
After a user logs on, a process is started to pass user operations to the kernel. This process is a command interpreter or a specific program (Shell) that the user logs on to the system and runs. Shell is the interface between users and Linux systems. There are many types of Linux Shell, each of which has different characteristics. Commonly used are sh (BourneShell), csh (CShell), ksh (KornShell), tcsh (TENEX/TOPS-20typeCShell), bash (BourneAgainShell) and so on. The system administrator can specify a Shell for the user based on the system conditions and user habits. If no Shell is specified, the system uses sh as the default logon Shell, that is, the value of this field is/bin/sh.
The user's logon Shell can also be specified as a specific program. This program is not a command interpreter ). With this feature, we can restrict the user to run only the specified application. After the application is running, the user automatically exits the system. In some Linux systems, only programs registered in the system can appear in this field.

In the system, a type of users are called pseudo-user psuedousers. These users also have a record in the Linux/etc/passwd file, but cannot log on because their logon Shell is empty. They are mainly used to facilitate system management and meet the file owner requirements of the corresponding system processes. Common pseudo-users are as follows.
False user meaning
Bin has executable USER command files
Sys owns system files
Adm has account files
UucpUUCP usage
Lplp or lpd subsystem usage
NobodyNFS usage
Owned account file
In addition to the pseudo applications listed above, there are also many standard pseudo users, such as audit, cron, mail, and usenet, which are also required by related processes and files.
Since Linux/etc/passwd files can be read by all users, if a user's password is too simple or regular, a common computer can easily crack it, therefore, Linux systems with high security requirements separate encrypted passwords and store them separately in a file. The file is a/etc/shadow file. Only a Super User has the permission to read the file, which ensures the security of the user's password.

  1. Detailed introduction to the creation of Linux batch users
  2. Describes how to create a Linux wap Gateway.
  3. Detailed command 1 for running Linux background)
  4. Parsing Linux NTFS partitions
  5. In-depth analysis of Linux partition Basics

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.