User Group Management includes creating, deleting, modifying, and viewing group operation commands for user groups. Let's take a look at the following. I hope this article will be helpful to you.
1. Create a group
Groupadd test
Add a test group
2. modify a group
Groupmod-n test2 test
Change the name of the test group to test2.
3. delete a group
Groupdel test2
Delete Group test2
4. View groups
A) view the group groups of the currently logged-on user and the group groups apac of the apacheuser.
1. Group operations
1. Create a group
Groupadd test
Add a test group
2. modify a group
Groupmod-n test2 test
Change the name of the test group to test2.
3. delete a group
Groupdel test2
Delete Group test2
4. View groups
A) view the groups group of the currently logged-on user and the groups apacheuser group of the apacheuser.
B) view all groups cat/etc/group
C) Some linux systems do not have the/etc/group file. Check the following method.
Cat/etc/passwd | awk-F [:] '{print $4}' | sort | uniq | getent group | awk-F [:] '{print $1 }'
The getent command is used here. You can use the group ID to find the group information. If this command does not exist, it is difficult to find all the groups in the system.
2. user operations
1. Add users
View copy print?
[Root @ krlcgcms01 mytest] # useradd-help
Usage: useradd [options] LOGIN
Options:
-B,-base-dir BASE_DIR: set the basic path as the user's logon directory.
-C,-comment COMMENT comments to users
-D,-home-dir HOME_DIR: Set the user's logon directory
-D,-defaults change settings
-E,-expiredate EXPIRE_DATE: Set the user's validity period
-F,-the password is invalid after the inactive INACTIVE user expires.
-G,-gid GROUP to make the user belong to only a GROUP
-G,-groups GROUPS allows users to join a group
-H,-help
-K and-skel SKEL_DIR specify other skel Directories
-K and-key KEY = VALUE overwrite the/etc/login. defs configuration file.
-M,-create-home automatically creates a logon directory
-L. Do not add users to the lastlog file.
-M: The logon directory is not automatically created.
-R: Create a system account.
-O,-non-unique allows users to have the same UID
-P,-password PASSWORD: Use the encrypted password for the new user
-S,-shell SHELL
-U,-uid UID specifies a UID for the new user
-Z,-selinux-user SEUSER use a specific SEUSER for the SELinux user mapping
[Root @ krlcgcms01 mytest] # useradd -- help
Usage: useradd [options] LOGIN
Options:
-B, -- base-dir BASE_DIR: set the basic path as the user's logon directory.
-C, -- comment COMMENT comments to users
-D, -- home-dir HOME_DIR: Set the user's logon directory
-D, -- defaults change settings
-E, -- expiredate EXPIRE_DATE set the user's validity period
-F, -- the password becomes invalid after the inactive INACTIVE user expires.
-G, -- gid GROUP to make the user belong to only a GROUP
-G, -- groups GROUPS allows users to join a group
-H, -- help
-K, -- skel SKEL_DIR specify other skel Directories
-K, -- key KEY key = VALUE overwrites the/etc/login. defs configuration file.
-M, -- create-home automatically creates a logon directory
-L. Do not add users to the lastlog file.
-M: The logon directory is not automatically created.
-R: Create a system account.
-O, -- non-unique allows users to have the same UID
-P, -- password PASSWORD: Use the encrypted password for the new user
-S, -- shell SHELL
-U, -- uid UID specifies a uid for the new user
-Z, -- selinux-user SEUSER use a specific SEUSER for the SELinux user mappinguseradd test
Passwd test
Add User test. Note that after adding a user to useradd, do not forget to set a password for the user. Otherwise, the user cannot log on.
2. Modify the user
Usermod-d/home/test-G test2 test
Change the logon directory of the test user to/home/test and add it to the test2 Group. Note that this is a big G.
Gpasswd-a test test2 add user test to test2 Group
Gpasswd-d test test2 remove user test from the test2 Group
3. delete a user
Userdel test
Delete user test
4. View users
A) view the current Login User
[Root @ krlcgcms01 ~] # W
[Root @ krlcgcms01 ~] # Who
B). view your username.
[Root @ krlcgcms01 ~] # Whoami
C) view the information of a single user
[Root @ krlcgcms01 ~] # Finger apacheuser
[Root @ krlcgcms01 ~] # Id apacheuser
D) view User Logon records
[Root @ krlcgcms01 ~] # Last view logon success user records
[Root @ krlcgcms01 ~] # Lastb view unsuccessful logon user records
E), view all users
[Root @ krlcgcms01 ~] # Cut-d:-f 1/etc/passwd
[Root @ krlcgcms01 ~] # Cat/etc/passwd | awk-F: '{print $1 }'
Usermod-g group loginname forcibly sets usermod-G groups loginname in the group where a user is located to change a user to group (s) usermod-a-G groups loginname to add the user to a group (s) should this be used? I have always used a program to change the GUI