[Linux study notes] 08_Linux user management

Reprint statement: For commercial reprints, please contact the author for authorization, and for non-commercial reprints, please indicate the source.  

basic introduction

User management diagram

image

illustrate

  • Linux system is a multi-user and multi-task operating system. Any user who wants to use system resources must first apply for an account to the system administrator, and then enter the system as this account.
  • Linux users need to belong to at least one group

Add user

basic grammar

useradd [options] username

actual case

Add a user xm.

image

Special Note

cd means change directory, switch directory

Details

  • When the user is successfully created, a home directory with the same name as the user will be automatically created
  • You can also specify a new user name for the directory through useradd -d, and specify the home directory for the newly created user

image

Assign or change a password for a user

basic grammar

passwd username

Applications

Specify a password for xm image

delete users

basic grammar

userdel username

Applications

  • Delete user xm, but keep the home directory
    • userdel username
  • Delete user and user home directory
    • userdel -r username

Precautions

When deleting a user, we generally do not delete the home directory

Query user information

basic grammar

id username

Applications

Please check root information

image

Details

When the user does not exist, return no such user

switch user

introduce

In operating Linux, if the current user has insufficient permissions, you can switch to a high-privileged user, such as root, through the su - command.

basic grammar

su – switch username

Applications

Create a user zf, specify a password, and switch to zf.

image

Details

  • Switching from a user with high authority to a user with low authority does not require entering a password, and vice versa.
  • When you need to return to the original user, use the exit command

View current user/login user

basic grammar

  • whoami
  • who am I

user group

introduce

Similar to roles, the system can manage multiple users with commonality in a unified manner.

Add group

groupadd group name

delete group

groupdel group name

Add groups directly when adding users

useradd -g user group username

Operation demonstration

Add a user zwj and assign him directly to wudang

image

Modify a user's group

usermod -g user group username

Case demonstration

image

User and group related files

/etc/passwd file

  • User (user) configuration file, recording various information of the user
  • The meaning of each line: Username: Password: User ID: Group ID: Commentary Description: Home Directory: Login Shell

image

/etc/shadow file

  • password configuration file
  • The meaning of each line: Login Name: Encrypted Password: Last Modified Time: Minimum Interval: Maximum Interval: Warning Time: Inactivity Time: Expiration Time: Flag

/etc/group file

  • The configuration file of the group (group) records the information of the groups included in Linux
  • The meaning of each line: group name: password: group identification number: list of users in the group

image

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324198207&siteId=291194637