When you use Linux, you need to log in as a user, limiting the resources that a consumer can access, and groups are used to facilitate the organization's management of users.
Users and Groups
• Each user has a UserID
• Each user belongs to a primary group, belonging to one or more subordinate groups
• Each group has a groupid
• Each process runs as a user and is limited by the resources accessible to that user
• Each landing user has a specified shell
The files in the system have a user and a group of which they belong, and the user and group information is stored in the following three files:
/ETC/PASSWD User Information
/etc/shadow User Password
/edc/group Group Information
The command ID is used to display the current user's information, the command passwd can modify the current user's password, and the following command can display the login user information:
WHOAMI Display Current User
WHO displays user information currently logged in
W Displays the login user's details
Command Useradd add a user:
Useradd User Name
-D Specify user home directory
-S Specify user login Shell
-u Specifies user uid
-g Specifies the primary group to which the user belongs
-g Specifies the subordinate group to which the user belongs
Command Usermod Modify a user's information:
Usermod parameter User name
-L Modify User name
-U Modify UID
-G Modify User main group
-G Modify User subordinate Group
-L Lock users
-U Unlock User
Example 1:
# useradd-d/usr/sam-m Sam
This command creates a user Sam where the-D and-m options are used to produce a home directory/usr/sam (/usr as the parent directory for the default user home directory) for the login Sam.
Example 2:
# useradd-s/bin/sh-g group-g adm,root Gem
This command creates a new user gem, whose login shell is/bin/sh, belongs to the group user group and belongs to the ADM and root groups, where the group user group is its primary group.
New groups may be created here: Groupadd Group and Groupadd ADM
Adding a user account is adding a record to the new user in the/etc/passwd file, while updating other system files, such as/etc/shadow,/etc/group.
Linux provides an integrated system management tool userconf, which can be used to manage user accounts uniformly.
Note:
The user account itself is defined in/etc/passwd. The Linux system contains a/etc/passwd companion file called/etc/shadow. This file, unlike/etc/passwd, is readable only for root users and contains encrypted password information
Command Userdel user to delete a user:
Userdel User Name
USERDEL-L user name deletes the user's home directory while deleting the user
Command Groupadd, Groupmod to create, modify a group:
Groupadd Group Name
Groupmod-n New group name old group name
GROUPMOD-G New group ID old group ID
For example:
# Userdel-r Sam
This command deletes the user Sam's record in the system files (primarily/etc/passwd,/etc/shadow,/etc/group, etc.) while deleting the user's home directory.
Delete a group
Similarly, we sometimes need to delete a group that commands Groupde to delete a group