One, group operations
1. Create a group
Groupadd Test
Add a test group
2. Modify the Group
Groupmod-n test2 Test
Change the name of the test group to Test2
3. Delete a group
Groupdel test2
Delete Group Test2
4. Viewing groups
A), view the group groupswhere the current logged-on user is located, and view the Apacheuser group groups Apacheuser
b), view all groups Cat/etc/group
c), some Linux systems do not have/etc/group files, this time to see the following method
CAT/ETC/PASSWD |awk-f [:] ' {print $4} ' |sort|uniq | Getent group |awk-f [:] ' {print $} '
Here a command is getent, you can find the group information through the group ID, if the command is not, it is difficult to find, all the groups in the system.
Second, user operation
1. Increase user
[[email protected] mytest]# useradd--help usage:useradd [options] LOGIN options:-B,--base-dir Base_dir Set the base path as the user's logon directory-C,--comment comment comments to the user-D,--home-dir Home_dir set the user's login directory-D,--defaults Change Settings-E,--expiredate expire_date set user's validity period-F,--inactive inactive user expires, leave password invalid-G,--gid GROUP Make the user belong to only one group-G,--groups groups let the user join a group-H,--help help-K,--skel Skel_dir Specify additional Skel directory-K,--key key=value overwrite/etc/login.defs profile-M,--create-home automatically create login directory-L, Do not add users to the Lastlog file-m, do not automatically create the login directory-R, establish the SYSTEM account -O,--non-unique allows users to have the same uid-p,--password password for new users using the encryption password-s,--shell Shell login Shell-u,--uid uid Specifies a uid-z for the new user,--selinux-user Seuser use a specific seuser for the Selinu X user Mapping
Useradd test
passwd test
Add user test, one thing to note, useradd add a user, do not forget to set a password for him, otherwise you can not log in.
2, modify the user
usermod-d/home/test-g test2 Test
Change the login directory of the test user to/home/test and join the Test2 group, note that this is the big G.
gpasswd-a test test2 Adding user test to the Test2 group
gpasswd-d test test2 to remove user test from the Test2 group
3. Delete users
Userdel Test
Remove the test user
4. View Users
A), view the currently logged in user
[Email protected] ~]# W
[email protected] ~]# who
b), view your user name
[Email protected] ~]# whoami
c), view individual user information
[Email protected] ~]# finger apacheuser
[[email protected] ~]# ID apacheuser
d), view user login record
[[email protected] ~]# Last view login successful user record
[[email protected] ~]# lastb View login unsuccessful user record
e), view all users
[Email protected] ~]# cut-d:-F 1/etc/passwd
[[email protected] ~]# cat/etc/passwd |awk-f \: ' {print $} '
Add, delete, modify, view users and user groups under Linux