Common Linux User Management

Source: Internet
Author: User

Body:

As a Linux User, basic user management is required. The main files related to user management include:
/Etc/passwd: records the root, system account, and general account of the system.
/Etc/shadow: record the password of each account in the system
/Etc/group: records all user groups in the system,
/Etc/gshadow:
User logon and file operations are performed by first viewing the UID and GID, and then displaying the corresponding name. After the user logs on to the system and enters the account and password:
First, determine the account to determine whether/etc/passwd has your input account. If yes, read the UID and GID, the main folder of the account and the corresponding default shell should also be read. The basic information is included in/etc/passwd.
Second, determine the password,/etc/shadow
1. file structures
1.1/etc/passwd file structure
The number of lines in the file indicates the total number of accounts in the system.
Instance: apple: x: 1000: 1000: apple, lab4:/home/apple:/bin/bash
A total of 7 fields,
1st fields: Account name
2nd fields: account password. Because the password is separately placed in shadow, it is displayed as x
3rd fields: UID
If the UID is 0, it indicates the system administrator. To make a user a system administrator, set UID to 0. UID = 1 ~ 499 indicates a system account, and 500 or more indicates a Logon account.
4th fields: GID, the user group to which the account belongs. It is mainly associated with/etc/group
5th fields: basic description of the account
6th fields: the user's main folder, used for the default folder that the user enters after login
7th fields: the default shell obtained after the user logs on
1.2/etc/shadow file structure
Instance: xiaolong: Qz9: 15708: 0: 99999: 7 :::
A total of 9 Fields
1st fields: Account name
2nd fields: the encrypted password. If this field exists before! Or * indicates "temporarily invalid" Password
3rd fields: Date on which the password was recently changed
4th fields: the number of days after the last password change date, no need to change the password again
5th fields: the number of days after the last password change date, the password needs to be changed again, that is, the number of days after the password is changed again
6th fields: the number of days before the password is about to be reset.
7th fields: the number of days after the password expires that the account is allowed to log on again
8th fields: the account cannot log on to the system after this date
9th fields: reserved fields
1.3/etc/group file structure
Instance: root: x: 0: root
4 fields in total
1st fields: User Group Name
2nd fields: password of the user group name
3rd fields: GID of the user group
4th fields: account names supported by the user group. If you want to add an account to a user group, you must add the account name to this field. However, usermod-G groupname username is generally used.
Note:
When an account is in a directory and a file is created, the Default User Group of the generated file is the valid user group of the account. You can use groups to view the user group of the current account, the first is a valid user group.
Newgrp groupname is used to change the valid user group of this account. newgrp is used to create a sub-shell in the Current shell for running. After running, use exit to return to the original environment. In the project development process, if you want to make a directory for only a few accounts to work collaboratively, you need to use
1, chgrp groupname dirname
2, chmod 2770 dirname
Explanation: 1 is mainly used to change the user group to which the directory belongs to the user group you need. However, if the user group is only 770 in the 2 operation, the user group of files generated by each account is determined by the current valid user group of the account. Generally, the valid user group of an account is the name of the account. Add 2 here, mainly using SGID. X in the second field is s. SGID can be used for files or directories. After using the directory, it has the following functions:
1) users can access the directory only when they have the r and x permissions on the directory.
2) The user's valid user group in this directory is the user group in this directory
3) The user creates a file in this directory. the user group of this file is the same as the user group in this directory.
Note: Changing file attributes and permissions
Chgrp [R]: Change the user group to which the file belongs
Chgrp [-R] user group name file or directory
Chown: Change the file owner:
Chown [-R] account name file or directory chown [-R] Account name: group name file or directory
-R indicates making recursive changes. It is generally used to change all subdirectories or files in a directory.
Chmod: change file permissions:
R: 4, w: 2, x: 1;
Chmod [-R] [rwx] [777] file or directory

Common commands for Linux User Management

Recommended reading:

RHEL5.6 useradd bug Solution

Details about useradd and adduser in CentOS and Ubuntu

Usage of Ubuntu 10.04 useradd and adduser

Basic Linux Tutorial:/etc/default/useradd file

Differences between useradd and adduser in Ubuntu

  • 1
  • 2
  • 3
  • Next Page

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.