Account Management under centos

Source: Internet
Author: User

In Linux, each file has three types of permissions: account permissions, group permissions, and other permissions. Accounts and groups are many-to-many relationships, that is, an account can belong to multiple groups, and a group can contain multiple accounts. However, for each logged-on account, only one effective group (initial group) exists ).

The configuration files related to account management are as follows: the account information file is/etc/passwd, the account password file is/etc/shadow, the group information file is/etc/group, and the group password file is/etc/gshadow.

1. view the/etc/passwd file

For example, in the/etc/passwd file, each row is an account, and each field separated by a colon means the following by serial number:

[1] account name. Rename usermod-l

[2] password. This field is enabled. Configure the account password in the/etc/shadow file

[3] uid, the unique ID of the account. Commands that affect the field value include: useradd-u, usermod-u

[4] GID, the unique ID of the initial group. It is associated with the 3rd fields in the/etc/group file. This group is the default valid group for the Account (the valid group can be switched using the newgrp command ). Commands that affect the field value include: useradd-G and usermod-G.

[5] description. Commands that affect the field value include: useradd-C, usermod-C

[6] absolute path of the home directory. Commands that affect the field value include: useradd-D, usermod-d

[7] shell: The shell enabled by the account by default. If it is/sbin/nologin, the account cannot log on. The shell that can be used by the account can be queried using the command CHSH-l (the query result is the content of the/etc/shells file ). Commands that affect the field value include: useradd-S, usermod-S

2. view the/etc/shadow file

 

For example, each line in the file/etc/shadow corresponds to the password information of an account. The meaning of each field separated by a colon is as follows:

[1] account name, associated with the 1st fields in the/etc/passwd file

[2] Password, encrypted ciphertext, encryptedAlgorithmIt is specified by encrypt_method in the/etc/login. defs file. Here it is sha512. Commands that affect the field value include: usermod-l (front !! Freeze), usermod-U (unfreeze), passwd-l (freeze), passwd-U (unfreeze ),

[3] creation date. A number is displayed, indicating the number of days that have elapsed since January 1. Commands that affect the field value include: chage-d

[4] How many days after a password is created can it be changed again? 0 indicates no such restriction. Commands that affect the field value include passwd-N and chage-M.

[5] The password will expire after several days of creation. The password will expire after 99999 days, which is about 99999/365 years. Several hundred years means the password will not expire. Commands that affect the field value include passwd-X and chage-M.

[6] How many days before the password expires to send a warning message to the user. Commands that affect the field value include passwd-W and chage-w.

[7] How many days can the password be extended after it expires? In this period, the user can log on and change the password. After this period, the user cannot log on. Commands that affect the field value include: useradd-F, usermod-F, passwd-I, chage-I

[8] expiry date, a number indicating the number of days that have elapsed since January 1. After this day, the user's password becomes invalid. no matter whether the password expires or not, you cannot log on again. Commands that affect the field value include: useradd-E, usermod-E, chage-e

[9] Reserved

3. view the/etc/group file

For example, each row of the file/etc/group corresponds to a group, and each field separated by a colon indicates the following by serial number:

[1] group name. Command for renaming: groupmod-n

[2] Password, enabled, and the group password is configured in the/etc/gshadow File

[3] GID, which uniquely identifies a group. It is associated with the 4th fields in the/etc/passwd file and serves as the initial group of the corresponding account. Commands that affect the field value include groupadd-G and groupmod-G.

[4] list of account names separated by commas. These accounts can actively switch to members of this group. For example, if you use mophee (the initial group is mophee), you can use the newgrp command to switch the valid group to MySQL or mail. Commands that affect the field value include: useradd-G, usermod-[a] G

4. view the/etc/gshadow File

For example, in the/etc/gshadow file, each line corresponds to the password information of a group. The meanings of each field separated by a colon are as follows:

[1] group name, corresponding to the group name in/etc/group

[2] Password, encrypted ciphertext. You can use the command gpasswd group_name to set the group password and use gpasswd-r group_name to delete the password.

[3] Group Administrator: Use the command gpasswd-A user1,... group_name to set the Group Administrator. Note: The group administrator can set a password for group members.

[4] group member. This field is the same as the 4th fields in/etc/group and must be modified synchronously. Besides the maintenance by using the useradd-G and usermod-G commands, you can also use gpasswd-[ADM] for maintenance. Commands that affect the field value include: useradd-G, usermod-[a] G

-----------------------------------------------

In theory, you can modify the above four configuration files to manage your account, but we do not recommend that you manage your account. Linux provides enough commands to manage the account. Although these commands actually modify the content of these four files, we recommend that you use these commands:

Useradd: add an account

 
Useradd mophee# Create a group mophee, create an account mophee, create a home directory/home/mophee, and set the permission to 700. You cannot log on without a password.Useradd-u 519-G users mophee2# Create an account mophee2, specify UID as 519, and specify the initial group as users.Useradd-r mophee3# Create a system account mophee3. The UID and GID range are: 100 ~ 499, no home directory

Usermod: Modify an account

Userdel: deletes an account.

Userdel mophee# Delete an account mophee: #1. Delete it from/etc/passwd and/etc/shadow; #2. Remove the last field from/etc/group and/etc/gshadow; #3. If the initial group has no other member accounts, delete the group.Userdel-r mophee# Besides deleting accounts, you can also delete their home directories and email directories.

Passwd: account password management

 
Passwd-s mophee# List password information related to the account mophee

Chage: Change the account password. You can use this command to change your password.

 
Chage-l mophee# List password information related to the account mophee

Groupadd: Add a group

Groupmod: modify a group

Groupdel: deletes a group.

Gpasswd: group password, Group Administrator, and member management

Groups: View groups

 
Groups mophee# List groups to which the account mophee belongs

Newgrp: switch to a valid group

----------------------------------------------

Other configuration files related to account management:/etc/login. defs,/etc/default/useradd (some default values when useradd is used ).

1. file/etc/default/useradd

Group: the default group ID.

Home: The base Directory of the home directory. Adding an account and creating a home directory is equivalent to creating a directory with the same name as the account under the base Directory, affecting the 6th fields of/etc/passwd.

Inactive: Set whether the password expires after expiration.-1 indicates that the password will not expire and affects the 7th fields in/etc/shadow.

Expire: Password Expiration date, which affects the 8th fields of/etc/shadow.

Shell: the default shell, which affects the 7th fields of/etc/passwd.

SKEL: creating a home directory is the initial content for reference. When you create a home directory, the content under this directory is copied to the home directory.

Create_mail_spool: whether to create the corresponding mailbox directory. YES/NO, yes, a directory with the same name as the account name will be created in the/var/spool/mail/directory to store emails of this account.

2. view the/etc/login. defs File

Mail_dir: The baseline directory of the mail directory, usually/var/spool/mail

Pass_max_days: the number of days that have elapsed since the password was created, affecting the 5th fields in/etc/shadow.

Pass_min_days: the number of days that cannot be changed after the password is created, affecting the 4th fields in/etc/shadow.

Pass_min_len: Set the shortest length allowed by the password. It is enabled and is replaced by the PAM module.

Pass_warn_age: Number of days before the password expires before the warning message is sent, affecting the 6th fields in/etc/shadow

Uid_min: uid smaller than the specified number is a system account. The default value is 500. The UID of the Account Added when useradd is used and the-r option is not added is greater than this value.

Uid_max: Maximum uid value supported by the system

Gid_min: similar to uid_min, which affects GID

Gid_max: similar to uid_max, which affects GID

Create_home: whether to create the home directory by default. Yes/No

Umask: The back code of the default permission of the home directory. If the value is 077, the permission of the home directory is 700.

Usergroups_enab: sets whether to delete an account if there is no other member account in the initial group when The userdel command is used to delete the account. Yes/No

Encrypt_method: encryption algorithm, such as sha512

Related Article

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.