Linux User management increased 、 Delete 、 Change 、 Check the user's configuration file for details .

linux User management of

linux Support multiple users to use the same user login system at the same time ,windows In the case of modifying group policy , You can also log in by multiple people using the same user .

Remote connection Linux The way :ssh

Remote connection windows The way :RDP

View the users in the system

[[email protected] ~]# id
# id, View the current login user information
-u To view the user uid
-g To view the user gid
-G View the user's group id
[[email protected] ~]# id -u gong01
[[email protected] ~]# id -g gong01
[[email protected] ~]# id -G gong01

User related profiles

User profile -passwd


[[email protected] ~]$ cat /etc/passwd
root user name
x Password placeholder
0 uid
0 gid
roor Annotation information
/root User home directory
/bin/bash The interpreter used by the user 

User password profile -passwd


[[email protected] ~]# cat /etc/shadow
First column user name
Second column !!  No password , The password
The third column 18351 from 1970 The first day of the year , The last time the password was changed was from 1970 How many days are there now .
The fourth column Minimum password usage days  0 Means unlimited
The fifth column Password expiration days ,99999 God
The sixth column Seven days before password expiration  7
The seventh column After the password expires n I'll force you to change your password
The eighth column Account expiration time , from 1970 It's starting to count in
Row 9 Retain 

Classification of users ( Appointment 、 standard )

user UID System meaning
0 The super user , Have the highest authority of the system
1-200 System users , The system is assigned to the system program , No need to log in to the system
201-999 System users , Used to run services , There is no need to log in to the system
1000+ Ordinary users

Be careful : stay CentOS

User related commands


useradd [options] [ user name ]
By default , When you create a user, you create a group with the same user name , And add users to it
-u Appoint uid
-g Appoint gid, You can also specify a generic group
-G Assign a generic group , Additional group ; If you join more than one additional group, use ',' Separate
-M Do not create a home directory
-s Designated login shell
-c notes
-d Specify home directory
-r Create a uid The scope is 201-999 Of the system users , Do not create a home directory .
-p Specify the password when creating 


Usage: userdel [options]  user name
By default , When deleting a user, the user group with the same name will also be deleted , But if there are other users in the group , The group is not deleted , Delete users only .
-r Delete users at the same time , Delete user's home directory , And other email directories of users  ( Delete clean )


Usage: usermod [options] username
-u modify uid
-g modify gid
-G Modify additional groups
-a coordination -G, When modifying additional groups , Play an additional effect
-m modify ( transfer ) Home directory , Must cooperate -d Use
-d Specify the modified home directory
-s Modify the login shell
-c Modify comment
-l Modify the login user name
-L Lock the user
-U Unlocking users 



User's extended knowledge

[[email protected] ~]# grep -vE '^#|^$' /etc/login.defs 
MAIL_DIR /var/spool/mail #  Specify the location of the mail file after the user is created
PASS_MAX_DAYS 99999  #  The maximum number of days for a password
PASS_MIN_DAYS 0 #  Minimum number of days for password
#  Minimum password length
#  Seven days before password expiration
#  For ordinary users uid minimum value
UID_MIN                  1000
#  For ordinary users uid Maximum
UID_MAX                 60000
#  Use -r  Create the user's minimum uid
SYS_UID_MIN               201
#  Use -r  Create the user's minimum uid
SYS_UID_MAX               999
#  Create the smallest uid
GID_MIN                  1000
#  Create the maximum number of groups uid
GID_MAX                 60000
#  Use -r  Create the smallest uid
SYS_GID_MIN               201
#  Use -r  Create the smallest uid
SYS_GID_MAX               999
Whether to create home directory by default
#  Default permissions when creating home directory 700
UMASK           077
# userdel Whether to delete the corresponding group when deleting
#  Encryption algorithm of user password
[[email protected] ~]# ll /etc/default/useradd 
-rw-r--r--. 1 root root 119 Oct 30  2018 /etc/default/useradd
[[email protected] ~]# cat /etc/default/useradd 
#  When /etc/login.defs   Medium USERGROUPS_ENAB by no Control here while you're at it .
#  The default home directory for ordinary users
#  Whether to enable account expiration suspension  -1  To stop
#  Account end date , Not set
#  The default when creating a user is shell
#  Copy the contents when creating , When users delete environment variables of home directory by mistake , You can copy the contents
#  Whether to create mail files when creating users

Password management for users

#  The specification for creating passwords
-  The length of the password should be greater than 10 Characters
-  Passwords contain uppercase and lowercase letters , And special characters  ! @ #
-  Irregularity  ( Don't show your name 、 Corporate name 、 Telephone 、 And simple passwords )
[[email protected] ~]# passwd --help
Usage: passwd [OPTION...] <accountName>
#  Change password for current user
[[email protected] ~]# passwd  
#  to test01 Change password
[[email protected] ~]# passwd test01
#  Use non interactive password change
[[email protected] ~]# echo 123 |passwd --stdin test01
# md5su encryption , And check it
echo $RANDOM|md5sum
# tee  Output at the terminal and append to the file
echo 123|tee a.txt
#  Password management command  
yum -y install expect
usage: mkpasswd [args] [user]
  where arguments are:
    -l #      (length of password, default = 9)
    -d #      (min # of digits, default = 2)
    -c #      (min # of lowercase chars, default = 2)
    -C #      (min # of uppercase chars, default = 2)
    -s #      (min # of special chars, default = 1)
-l Password length
-d Numbers
-c Lowercase letters
-C Capital
-s Special characters