User groups
Groupadd: Adding user groups
Basic format: groupadd-g GID group_name
Example: Add a user group with a GID of 501,group_name as DBA,
Enter "GROUPADD-G 501 DBA"
Groupdel: Deleting a user group
Basic format: Groupdel group_name
Example:
1), delete a user group named Test, and the test group does not belong to any user's primary group,
Enter "Groupdel test"
2), delete a user group named Test, and the test group is the primary group of Indigo users,
Set the Indigo user's primary group to another user group, or delete the Indigo user first,
Then enter "Groupdel test"
If not, first set the Indigo User's primary group to another user group, or delete the Indigo user,
The error "Groupdel:cannot remove user's primary group."
Groupmod: Set GID value
Basic format: groupmod-g GID group_name
Example: Set the GID of the test user group to 503 and enter "GROUPMOD-G 503 test"
Cat/etc/group: Viewing user group list information
Basic format: Enter "Cat/etc/group" directly at the command prompt
User
Useradd: Adding users
Basic format: Useradd [-u] [UID] [-g] [p_group_name] [-g] [group_name] User_name
Option Description:
-U: Represents the value created by the user to enter the UID
UID: A value greater than 500
-G: Represents the primary group to which the created user belongs
P_group_name: Primary Group name
-G: Represents the satellite group to which the created user belongs
Group_name: Name of the subsidiary group
User_name: Indicates the name of the user to be created
Example:
1), directly enter "Useradd user_name", such as creating a user named Sam,
Enter "Useradd Sam" to create a user with the same name as the user
User groups
2), create an Oracle user, UID 550, Primary group is Oinstall, subordinate group is DBA,
Enter "Useradd-u 550-g oinstall-g dba Oracle"
If the Oinstall group and the DBA group do not exist when the Oracle user is created, an error is thrown,
So be sure to ensure the existence of the Oinstall Group and the DBA group at the time of creation
Userdel: Deleting users
Basic format: Userdel [-R] User_name
Option Description:
-R: Remove all information related to all users to be deleted
USER_NAME: The user name to delete
Example:
1), delete only utest users, do not delete user-related information, enter "Userdel utest"
After you delete a user using this method, if you need to create the same user, an error is thrown,
In this case, you need to first delete the directory under the/home directory and the associated file directory utest.
Remove the Utest file from the/var/mail directory again
2), delete utest users and related information, enter "Userdel-r utest"
Usermod: Set user uid, primary group, subordinate group and other information
Basic format: Usermod [-u] [UID] [-g] [p_group_name] [-g] [group_name] User_name
Option Description:
-U: Indicates the need to enter a UID value
UID: Value not less than 500
-G: Indicates the need to enter the primary group name
P_group_name: Primary Group name
-G: Indicates that additional group names need to be entered
Group_name: Additional group name
User_name: User name that needs to be set
Example:
1), set the UID of the Utest user to 510, enter "Usermod-u 510 utest"
2), set Utest user's primary group as Oinstall, enter "Usermod-g oinstall utest"
3), set Utest user's additional group as DBA, enter "Usermod-g dba utest"
4), set Utest user's primary group is Oinstall, additional group is DBA,
Enter "Usermod-g oinstall-g dba Utest"
5), set Utest user UID is 510, primary group is Oinstall, additional group is DBA,
Enter "Usermod-u 510-g oinstall-g dba utest"
ID: View user information, such as Uid,gid, primary group, satellite group, etc.
Basic format: ID user_name
Example: View Utest user's information, enter "ID utest"
SU: Switching users
Basic format: su [-] user_name
Example: The current user is root
1), switch the current user to utest, but do not switch environment variables, enter "Su utest"
2), switch the current user to utest, and switch environment variables, enter "Su-utest"
CAT/ETC/PASSWD: Viewing user list information
Basic format: Enter "CAT/ETC/PASSWD" at the command prompt
Three user and user group actions for linux Command learning notes