Linux的使用者和組之設定檔詳解 Linux系統以組Group方式系統管理使用者 有關使用者和組的配置和管理檔案主要有:/etc/passwd/etc/shadow/etc/group/etc/gshadow/etc/login.defs/etc/default/useradd 下面詳細介紹這些設定檔 /etc/passwd: 設定和存放使用者資訊,檔案格式如下: 使用者名稱 :密碼 :UID :GID :使用者描述 :使用者主目錄 :登入shell版本 樣本: root:x:0:0:root:/root:/bin/bash mqm:x:495:501::/var/mqm:/bin/bash mysql:x:494:489:MySQL server:/var/lib/mysql:/bin/bash /etc/shadow: 由pwconv命令根據/etc/passwd自動產生,可簡單理解為/etc/passwd的加密版,檔案格式如下: 登入名稱 :加密口令 :最後修改時間 :最小時間間隔 :最大時間間隔 :警告時間 :不啟用時間 :失效時間 :標誌 樣本: root:$1$UNwzoVBB$9hMVimoum963DcADQ/QPz1:15758:0:99999:7::: mysql:!!:15783:::::: mqm:$1$17zCEo50$.DFU6Gm6wZ/i5LcHpfGt90:15761:::::: /etc/group: 設定和存放組Group資訊,檔案格式如下: 組名 :組群口令 :GID :所屬組的使用者 樣本: root:x:0:root,mqm bin:x:1:root,bin,daemon mqm:x:501:mqm,jww /etc/gshadow: 由pwconv命令根據/etc/group自動產生,可簡單理解為/etc/passwd的加密版,檔案格式如下: 組名 :組口令 :組管理員名稱 :群組成員名稱 root:::root,mqm bin:::root,bin,daemon mysql:!:: /etc/login.defs:建立使用者和組時,定義新使用者或組的預設設定,如是否需要使用者主目錄,密碼長度約束,UID和GID的數值範圍,使用者的期限等 對於相同配置選項,/etc/shadow的配置優先順序高於 /etc/login.defs //使用者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 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//通過useradd命令添加使用者時,uid的數值範圍## Min/max values for automatic uid selection in useradd#UID_MIN 500UID_MAX 60000 //通過groupadd命令添加使用者時,gid的數值範圍## Min/max values for automatic gid selection in groupadd#GID_MIN 500GID_MAX 60000 //刪除使用者時,是否執行USERDEL_CMD命令## 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 //通過useradd命令添加使用者時,預設是否為使用者建立使用者主目錄//可以被useradd命令的-m參數覆蓋## 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 //是否在執行userdel命令時刪除空組# This enables userdel to remove user groups if no members exist.#USERGROUPS_ENAB yes//密碼的加密方式# Use SHA512 to encrypt password.ENCRYPT_METHOD MD5MD5_CRYPT_ENAB yes /etc/default/useradd:設定添加的使用者的預設規則,如定義預設使用者主目錄、shell、環境檔案目錄、郵件緩衝等# useradd defaults file#表示可建立普通組GROUP=100#表示使用者主目錄的父目錄路徑HOME=/home#是否啟用帳號到期停權,-1表示不啟用INACTIVE=-1#帳號終止日期,不設定表示不啟用。EXPIRE=#所用SHELL的類型SHELL=/bin/bash#使用者主目錄的預設檔案來源SKEL=/etc/skel#是否建立使用者郵件緩衝CREATE_MAIL_SPOOL=yes