linux系統是通過文件來保存配置的,其中關于用戶和組的配置文件包括以下幾個:
/etc/passwd
/etc/shadow
/etc/group
/etc/gshadow
/etc/login.defs
/etc/default/useradd
/etc/passwd
存放用戶信息的配置文件,其基本格式如下
root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin adm:x:3:4:adm:/var/adm:/sbin/nologin lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
其中分隔符為冒號“:”,具體信息為
用戶名:
用戶密碼:顯示為x,因為真正的密碼保存在/etc/shadow中
用戶UID:
用戶GID:
用戶描述信息:
用戶家目錄:
用戶默認shell
/etc/shadow
root:$1$CVHlfpOK$DWkuyehOW/0RD49FE/6gx0:17094:0:99999:7::: bin:*:16659:0:99999:7::: daemon:*:16659:0:99999:7::: systemd-bus-proxy:!!:17063:::::: systemd-network:!!:17063:::::: dbus:!!:17063:::::: pirate:$1$86TXHfwN$YnY48R1.sngOB4Ms6Ipxi/:17063:0:99999:7:::
shadow的文件格式也是使用冒號“:”作為分隔符,具體內容為;
用戶名:
用戶(加密后的)口令:以$作為分隔符,前面的為salt,后面的為加密后的密碼
用戶上一次修改口令的時間:
用戶修改口令的最小時間間隔:
用戶口令最長使用時間:
用戶口令過期提前多久警告:
用戶口令過期之后多久會鎖定用戶:
用戶有效期:
保留字段,目前為空
/etc/group
root:x:0: bin:x:1: daemon:x:2: sys:x:3: adm:x:4: tty:x:5: mail:x:12:postfix
用戶組名稱:
用戶組口令:
用戶組GID:
組內用戶列表
/etc/gshadow
root::: bin::: daemon::: sys::: adm::: tty::: disk:::
用戶組名稱:
用戶組密碼:
用戶組管理員:
用戶組成員
/etc/login.defs
# # Please note that the parameters in this configuration file control the # behavior of the tools from the shadow-utils component. None of these # tools uses the PAM mechanism, and the utilities that use PAM (such as the # passwd command) should therefore be configured elsewhere. Refer to # /etc/pam.d/system-auth for more information. # #用戶mail設置: # *REQUIRED* # Directory where mailboxes reside, _or_ name of file, relative to the # home directory. If you _do_ define both, MAIL_DIR takes precedence. # QMAIL_DIR is for Qmail # #QMAIL_DIR Maildir MAIL_DIR /var/spool/mail #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 99999 #密碼有效期 PASS_MIN_DAYS 0 #密碼最短修改時間 PASS_MIN_LEN 5 #密碼最短長度 PASS_WARN_AGE 7 #密碼過期之前警告時間 # # Min/max values for automatic uid selection in useradd # UID_MIN 1000 #用戶最小UID UID_MAX 60000 #用戶最大UID # System accounts SYS_UID_MIN 201 #最小系統UID SYS_UID_MAX 999 #最大系統UID # # Min/max values for automatic gid selection in groupadd # GID_MIN 1000 #最小GID GID_MAX 60000 #最大GID # System accounts SYS_GID_MIN 201 #最小系統GID SYS_GID_MAX 999 #最大系統GID # # If defined, this command is run when removing a user. # It should remove any at/cron/print jobs etc. owned by # the user to be removed (passed as the first argument). # #USERDEL_CMD /usr/sbin/userdel_local # # If useradd should create home directories for users by default # On RH systems, we do. This option is overridden with the -m flag on # useradd command line. # CREATE_HOME yes #默認創建家目錄 # The permission mask is initialized to this value. If not specified, # the permission mask will be initialized to 022. UMASK 077 #默認umask # This enables userdel to remove user groups if no members exist. # USERGROUPS_ENAB yes #如果用戶被刪除之后,其組里面沒有用戶,刪除組 # Use SHA512 to encrypt password. ENCRYPT_METHOD SHA512 #口令加密方式 MD5_CRYPT_ENAB no
/etc/default/useradd
# useradd defaults file #創建用戶的默認設置 GROUP=100 #表示可創建普通組 HOME=/home #默認用戶家目錄的父目錄 INACTIVE=-1 #是否啟用帳號過期停權,-1表示不啟用 EXPIRE= #帳號終止日期,不設置表示不啟用 SHELL=/bin/bash #用戶默認shell SKEL=/etc/skel #用戶主目錄的默認文件來源 CREATE_MAIL_SPOOL=yes #是否創建用戶郵件緩沖
原創文章,作者:wangshuai,如若轉載,請注明出處:http://www.www58058.com/54618