Linux Account Management
1. Add a user
Add User using useradd command
useradd [-c comment] [-d home_dir] [-e expire_date] [-f inactive_time] [-g initial_group] [-G group[,...]] [-m [-k skeleton_dir] | -M] [-n] [-o] [-p passwd] [-r] [-l] [-s shell] [-u uid] login
-C description column-d specifies the main folder, instead of the default-e account expiration date-f shadow Field 7 option, whether the password expires, -1 is the group name that never takes effect-g initial user group-G this account can also join-m User main directory if it does not exist then create, if set-k, the files under skeleton_dir will be copied to the main directory. -M: do not create the user's main directory. The default value of the system account is-s shell-u user uid.
View useradd default values
# useradd -DGROUP=100HOME=/homeINACTIVE=-1EXPIRE=SHELL=/bin/bashSKEL=/etc/skel
The data provides the reference directory for the SKEL user main folder in the/etc/default/useradd file. When creating a user, copy the data from this directory to the user's main directory, including. bashrc,. bash_profile, etc.
User UID/GID, and some Password parameters. Their reference values are in/etc/login. defs
#QMAIL_DIR MaildirMAIL_DIR /var/spool/mail#MAIL_FILE .mail# Password aging controls:## PASS_MAX_DAYS Maximum number of days a password may be used.# PASS_MIN_DAYS Minimum number of days allowed between password changes.# PASS_MIN_LEN Minimum acceptable password length.# PASS_WARN_AGE Number of days warning given before a password expires.#PASS_MAX_DAYS 99999PASS_MIN_DAYS 0PASS_MIN_LEN 5PASS_WARN_AGE 7## Min/max values for automatic uid selection in useradd#UID_MIN 500UID_MAX 60000## Min/max values for automatic gid selection in groupadd#GID_MIN 500GID_MAX 60000## If useradd should create home directories for users by default# On RH systems, we do. This option is ORed with the -m flag on# useradd command line.#CREATE_HOME yes
2. modify a user
Change passwd Password
passwd [--stdin] usernamepasswd username
Stdin: You can change the password through MPs queue.
echo "adcd" | passwd --stdin user1
Passwd does not add an account to change the current user password-l: lock the password, add in the second column of/etc/shadow !, Invalidate the password. -U; unlock-S; List password-related parameters
You can also use chage to view user information.
# chage -l user1Minimum: 0Maximum: 99999Warning: 7Inactive: -1Last Change: Dec 27, 2014Password Expires: NeverPassword Inactive: NeverAccount Expires: Never
When an error occurs in useradd settings, you can use usermod to modify the information.
# usermod -husage: usermod [-u uid [-o]] [-g group] [[-a] -G group,...] [-d home [-m]] [-s shell] [-c comment] [-l new_name] [-f inactive] [-e expire ] [-p passwd] [-L|-U] name
3. delete a user
Userdel delete user
# userdel -r help
-R is deleted along with the main folder.
4. View user information
Finger: the user information can be queried, and the current user can be queried without a user name.
# finger workLogin: work Name: (null)Directory: /home/work Shell: /bin/bashOn since Sat Dec 27 17:20 (CST) on pts/1 from yongang.m 14 minutes 15 seconds idleNo mail.No Plan.
Chfn: modify this information: change finger
Id: View uid Information
[root@www home]# iduid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel)[root@www home]# id workuid=500(work) gid=502(work) groups=502(work)
5. Add a group
Groupadd is used to create a user group.
groupadd [-g gid] [-r] groupname
-G: specified group id-r: System User Group
6. modify a group
Groupmod
groupmod [-g gid] [-n old_groupname] groupname
-G: id of the group to be modified-n: name of the group to be modified
7. delete a group
Groupdel Delete Group
groupdel groupname
When deleting a user group, you must first Delete the user; otherwise, the user cannot be deleted.
8. User Group Administrator
Gpasswd is used to set the Group Administrator.
# gpasswdusage: gpasswd [-r|-R] group gpasswd [-a user] group gpasswd [-d user] group gpasswd [-A user,...] [-M user,...] group