User-related operations
Article Directory
learning target
- Create a user can know the command
1. Create a user
command | Explanation |
---|---|
useradd | Create (add) a user |
useradd command options:
Options | Explanation |
---|---|
-m | Automatically create the user's home directory, home directory name is the user name |
-g | User group the user belongs, do not specify the default will automatically create a user group with the same name |
Create a user renderings:
View all user information file renderings:
Description:
- useradd use the command requires administrator privileges, front need to add sudo
- If you do not specify a user to create a user group, the default will automatically create a user group with the same name
- Check whether the user has been created, you can view ** / etc / passwd ** This file
- View user group is created, you can check ** / etc / group ** This file
Each information Description passwd file to root❌0: 0: root: / root: / bin / bash as an example:
- First: Username
- Second: Password placeholder
- Third: uid, user id
- Fourth: gid, user's group id
- Fifth: user description, optional
- Sixth: the location of the user's home directory
- Seventh: The type of shell with a user, typically a bash or sh, sh type is not set by default
Each group file description information to laowang❌1001: for example:
- The first one: User Group Name
- Second: password placeholder user groups, user group Linux system generally do not have a password
- Third: the group id
id command to view the user information:
command | Explanation |
---|---|
id | View user information |
id command renderings:
each item of information Description:
uid = 1001 (laowang) gid = 1001 (laowang) group = 1001 (laowang)
- The first: uid represents the user id
- Second: gid indicating the user group id
- Third: Group means that the user where the user group
2. Set password
Other users to set a password, use: sudo passwd username
Password renderings:
3. Switch user
command | Explanation |
---|---|
his | Switch User |
Syntax: su - username
FIG handover user effects:
In laowang user sudo -s renderings:
Solution:
- Laowang provided to a user sudo additional group is required to modify the user information usermod
4. Modify User Information
command | Explanation |
---|---|
usermod | Modify user information |
usermod options:
command | Explanation |
---|---|
-G | An additional group settings |
-g | Modifying User Groups |
usermod command renderings:
After setting additional groups sudo, the switch to an administrator sudo -s FIG user effects:
5. Expansion: delete additional groups
command | Explanation |
---|---|
gpasswd | Add and remove additional group information |
gpasswd command options:
Options | Explanation |
---|---|
-a username | To add additional user groups |
-d username | To delete additional user group |
Delete additional groups renderings:
Delete additional group again using sudo -s renderings:
5. Delete User
command | Explanation |
---|---|
userdel | delete users |
userdel command options:
Options | Explanation |
---|---|
-r username | Delete the user's home directory must be set, otherwise the user's home directory will not be deleted |
Delete User renderings:
View user id information renderings:
View group file information renderings:
Description:
- Delete a user, the default user group with the same name will be deleted
6. Summary
- Create a user command format: sudo useradd -m user name , the default will create a user group of the same name.
- View user information using the id command or / etc / passwd file
- View user group information using the / etc / group file
- To the user password using sudo passwd user name
- Switch users using su - username
- Set up additional groups using sudo usermod -G group name Username
- Delete users sudo userdel -r user name , the same name as the default user group will be deleted.