Advanced Tutorial: parsing Passwd files in Linux

Source: Internet
Author: User
Article Title: advanced tutorial: parsing Passwd files in Linux. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

In Linux, users' key information is stored in the system's/etc/passwd file. Each valid user account of the system corresponds to a row of records in the file. This line of records defines the attributes of each user account.

The following is an example of a passwd file (partial excerpt ):

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

Bin: x: 1: 1: bin:/sbin/nologin

Daemon: x: 2: 2: daemon:/sbin/nologin

......

Desktop: x: 80: 80: desktop:/var/lib/menu/kde:/sbin/nologin

Mengqc: x: 500: 500: mengqc:/home/mengqc:/bin/bash

In this file, the data segments of each row of user records are separated by ":", which defines various user attributes. The order and meaning of each field are as follows:

Registration Name: Password: User ID: Group ID: User name: User main directory: Command Interpreter

(1) Registration Name (login_name): used to distinguish different users. The registration name is unique in the same system. In many systems, this field is limited to 8 characters (letters or numbers). Note that letters are usually case sensitive in Linux. This is different from MSDOS/Windows.

(2) passwd: The system uses a password to verify the validity of the user. Super User root or some advanced users can use the system command passwd to change the passwords of all users in the system. Common users can also use the passwd command to change their passwords after logging on to the system.

In current Unix/Linux systems, passwords are no longer directly stored in the passwd file. Generally, the password field in the passwd file is replaced by an "x, use/etc/shadow as a real password file to save data including personal passwords. Of course, shadow files cannot be read by common users. Only Super Users have the right to read them.

In addition, it should be noted that if the first character in the passwd field is "*", it means that the account is blocked and the system does not allow users with this account to log on.

(3) User ID (UID): UID is a numerical value and the only user ID in Linux system. It is used to distinguish different users. Use the UID field to manage processes and file protection in the system. In Linux, both the registration name and UID can be used to identify the user, but the UID is more important for the system. For users, the registration name is more convenient to use. For some specific purposes, there may be multiple users with different registration names but the same UID in the system. In fact, these users with different registration names are actually the same user.

(4) group ID: This is the default workgroup ID of the current user. Multiple users with similar attributes can be assigned to the same group. Each group has its own group name and is distinguished by its own group ID. Like UID, the user's group ID is also stored in the passwd file. In modern Unix/Linux, each user can belong to multiple groups at the same time. In addition to specifying the basic group in the passwd file, you can also specify a group of users in the/etc/group file.

(5) user_name: contains information about the user, such as the real name, office address, and contact number of the user. In Linux, mail, finger, and other programs use this information to identify the users of the system.

(6) user home directory (home_directory): this field defines the Home Directory of an individual user. After a user logs on, his Shell uses this directory as the working directory of the user. In Unix/Linux systems, the root working directory is/root, while other individual users have their own independent working environments under the/home directory, the system configures its own home directory for each user in this directory. Files of individual users are stored in their respective home directories.

(7) Shell: Shell is the name of a program that runs when you log on to the system. It is usually the full path name of a Shell program, such as/bin/bash.

Note that the system administrator usually does not need to directly modify the passwd file. Linux provides some account management tools to help the system administrator create and maintain user accounts.

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.