User and user group identifier
UID: UserID (user ID), the basis for the system to identify users, similar to our ID number.
User classification UID
administrator user 0
system user 1-999 (starting with CentOS7) 1-499 (CentOS7 Before)
Ordinary user 1000+ 500+
GID: GroupID (user group ID), the basis for user identification user group
User group classification GID
Administrator group 0
System user group 1-999 (starting with CentOS7) 1-499 (before CentOS7)
ordinary users Group 1000+ 500+
User-related configuration file
/etc/passwd User information-related configuration file
Each line corresponds to a user, with the same format:
root: x: 0:0: root: /root:/bin/bash
username: placeholder for password : UID: GID: User’s description information: Home directory: default shell
1. User name
2. A placeholder for password. If x is deleted, the user will not have a password
3. UID
4, GID
5, user description information
6. User home directory
7, shell environment user login
/ bin / bash means that the user can log in, using bash
/ sbin / nologin can not log into the system
/etc/shadow password information file
root: 6 66 qhBrffJ9nLQi.oN2 $ DRtEktcqvfS8osR42YnmvAHygAvIzovorycTKVTMaNhHYTtHgg / hOplOoIxlZAq8Uu8KJaEEZZfXJxic6nNbV1 :: 0: 99999: 7 :::
1, the user name
2, encrypted passwords
3, last modification date password
4, the minimum age of 0 indicates that the password can be modified at any time 1 represents 1 Password can be modified after days
5. Password validity period 99999 means it will never expire
6. Password expiration warning
7. Grace period, how long the password can be used after it expires
8. Account validity period
9. Retention
Classification of groups (relative to users)
Basic group
When creating a user, a group with the same name as the user name is automatically created. This is the basic group.
Additional groups (extra groups)
are other groups besides the basic group.
Private groups
are The basic group of a user has no other users, it is called private group
useradd Create user
useradd [Options] User name
-u specifies UID
-g specifies GID or group name
-G specifies additional group
-c user's comment information
-d specifies user Home directory
-s Shell of the specified user
For example: -s /sbin/nologin
-M Do not create a home directory, usually combined with -s
-r Create system user
-e Set user expiration date, format YYYY-MM-DD
Exercise:
1. Create a user: zhangsan
:useradd zhangsan
2. Create a user: lisi, description information: 4444444
:useradd -c 4444444 lisi
3. Create a user: wangwu, specify UID: 1521, home directory: /opt/wangwu
:useradd -u 1521 -d /opt/wangwu wangwu
4. Create a user: yanxiaoliu, UID: 1520, basic group: lisi, default shell is /bin/tcsh
useradd -u 1520 lisi -g lisi -s /bin/tcsh yanxiaoliu
5. Create a system user
User name: ops15
Note: admin
home directory: /opt/ops15
Basic group: root
useradd -r -c admin -d /opt/ops15 -g root
usermod modify the user
usermod [options] username
-c modify the user's comment
-d modify the user's home directory
-e modify the user's validity period
-g modify the basic group the
user belongs to -G modify the additional group the user belongs to
-l modify the user name ( Lowercase L)
-L lock user
-U unlock user
-u modify the user's UID
-s modify the user's default shell
-m move files in the user's home directory
Exercise:
1. Add user sc01
2. Modify user sc01, change the user name to sc02 and UID to 1905
userdel delete user
userdel [option] username
-r delete user's home directory and mailbox at the same time
Example:
userdel sc02
userdel -r admin123
User group management
User group configuration file
/etc/group User group information
root❌0:
1, group name
2, placeholder for group password
3, GID
4, group members
Create user group
groupadd [options] group name
Options:
-g specifies GID
-r to create a system user group
[root@ops14 ~]# groupadd ops14
[root@ops14 ~]# tail -1 /etc/group
ops14❌1002:
[root@ops14 ~]# groupadd -g 1010 ops1402
[root@ops14 ~]# tail -1 /etc/group
ops1402❌1010:
[root@ops14 ~]# groupadd -r ops1403
[root@ops14 ~]# tail -1 /etc/group
ops1403❌982:
Modify user group
groupmod [options] group name
-g GID modify GID
-n new group name to modify the group name modify the group name
[root@ops14 ~]# groupmod -g 10010 ops14 #Modify GID
[root@ops14 ~]# groupmod -n sc14 ops14 #Change the group name of ops14 to sc14
[root@ops14 ~]# groupmod -g 10018 -n ops14 sc14 #Modify GID and modify group name
Delete user group
groupdel [options] group name
For example:
groupdel ops14
Exercise:
1. Create a user group Linux, GID: 2019
groupadd -g 2019 Linux
2. Create user group Oracle, GID: 2020
groupadd -g 2020 Oracle
3. Check the last five lines of /etc/group to check whether the Linux and Oracle user groups are created successfully
tail -5 /etc/group
4. Modify the GID of Linux to 2018
groupmod -g 2018 Linux
5. Modify Oracle's GID to 2021, and the group name to Mysql
groupmod -g 2021 -n Mysql Oracle
6. Delete the Linux group
groupdel Linux
7. Delete the Mysql group
groupdel Mysql
Related commands
Set user password
passwd Set and modify password
passwd [Options] Account
-l --lock lock account
-u --unlock unlock account -stdin
read password from standard input
Example:
id displays the UID and GID of the user
groups show the user's group
su switch user
su [-] username
Note: If su does not follow the-symbol, after switching the user, it will stay in the directory where the user was before switching
exit exit user