1. Create a user
The command | instructions |
---|---|
useradd | Create (add) a user |
Useradd command options:
options | instructions |
---|---|
-m | The user home directory is automatically created. The name of the home directory is the user name |
-g | Specify the user group to which the user belongs. By default, the system does not automatically create a user group with the same name |
Create user renderings:
View file renderings of all user information:
Description:
- To use the useradd command, you need administrator privileges and sudo in front of it
- Creating a user If you do not specify a user group, the system automatically creates a user group with the same name by default
- To check whether the user is created successfully, view the /etc/passwd file
- To check whether the user group is created successfully, view the /etc/group file
The following uses root❌0:0:root:/root:/bin/bash as an example:
- First: username
- Second: password placeholder
- Third: UID, user ID
- The fourth gid is the id of the group to which the user belongs
- Fifth: User description, optional,
- Sixth: the location of the user’s home directory
- The shell type used by the user is bash or sh. The default shell type is not sh
The following uses laowang❌1001: as an example:
- First: user group name
- Second: user group password placeholder, general Linux system user groups do not have a password
- Third: group ID
The id command is used to query user information.
The command | instructions |
---|---|
id | Viewing User Information |
Each information description:
Uid = 1001 (laowang) gid = 1001 (group laowang) = 1001 (laowang)
- The first: uid represents the user ID
- The second: gid indicates the user group ID
- Third: Group Indicates the user group to which the user belongs
2. Set a password
To set a password for another user, use the sudo passwd username
Setting password effect picture:
3. Switch users
The command | instructions |
---|---|
su | Switch the user |
Syntax: su – User name
Switching user effect picture:
In laowang users using sudo-s rendering:
4. Delete the user
The command | instructions |
---|---|
userdel | Delete user |
Userdel command options:
options | instructions |
---|---|
The -r username | To delete the user home directory, you must set this parameter; otherwise, the user home directory will not be deleted |
Delete user renderings:
Id View user information effect picture:
View group file information effect picture:
Description:
- If you delete a user, the default user group with the same name will also be deleted
5. Summary
- To create a user, run the sudo useradd -m command. By default, a user group with the same name is created.
- To view user information, run the id command or the /etc/passwd file
- Set the password for the user using sudo passwd username
- To switch users, run the su – user name command
- Deleting a user If you run the sudo userdel -r username, the user group with the same name will be deleted by default.
note
If you have any questions or suggestions, please add wechat: 13960699696.