One, group operations
1, create a group
Groupadd Test
Add a test group
2, modify Group
Groupmod-n test2 Test
Change the name of the test group to Test2
3, deleting 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.
Two, user operation
1, increase the user
View copy print?
- [Email protected] mytest]# Useradd--help
- Usage:useradd [Options] LOGIN
- Options:
- -B,--base-dir Base_dir set the base path as the user's login 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 the user's validity period
- -F,--inactive inactive the password is invalid after the user expires
- -G,--gid group enables users to belong to only one group
- -G,--groups groups enables users to join a group
- -H,--help help
- -K,--skel Skel_dir Specify a different Skel directory
- -K,--key key=value overwrite/etc/login.defs configuration file
- -M,--create-home automatically create login directory
- -L, do not add the user to the Lastlog file
- -M, do not create the login directory automatically
- -R, set up the system account
- -O,--non-unique allows the user to have the same UID
- -p,--password password use encrypted password for new user
- -S,--shell Shell login Time Shell
- -U,--uid uid specifies a UID for the new user
- -Z,--selinux-user seuser use a specific seuser for the selinux 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 user
Userdel Test
Remove the test user
4. View Users
A) to view the currently logged on user
[Email protected] ~]# W
[email protected] ~]# who
b), view your user name
[Email protected] ~]# whoami
c) To view individual user information
[Email protected] ~]# finger apacheuser
[[email protected] ~]# ID apacheuser
d) To view user login records
[[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