一.用戶和用戶組配置文件主要有四個:/etc/passwd /etc/shadow /etc/group /etc/gshadow ,一個用戶或用戶組被創建后,系統會自動將相關信息添加到這4個文件.
1./etc/passwd
[root@Web ~]# head -2 /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologinbin
要點: 1.用戶分為偽用戶和真實的用戶. 偽用戶(bin)是系統創建的,不能登入(nologinbin)
2.每一行代表一個用戶的信息,有7個字段,用:分割
root:x:0:0:root:/root:/bin/bash
root (第1個字段): 用戶名
x (第2個字段): 密碼標識符
0 (第3個字段):用戶uid 0表示root用戶 1~499 標識偽用戶 500~ 標識創建的用戶
0(第4個字段):GID 初始用戶組 當用戶創建時,系統會默認生成一個與uid相同的GID
root(第5個字段): 用戶說明,相當於備注
/root(第6個字段): 用戶的家目錄
/bin/bash(第7個字段):用戶登入后使用的shell
2. /etc/shadow
[root@Web ~]# head -2 /etc/shadow
root:$6$jmM2rFzPCFbmqBkf$oz3AUooR3qaV5uXU67HcXlYiE3hNf0sSsunk1eBTDPrGUOM1xYCyesGoj.ZLTIzdiXEdrnnqNyC5g8SsRnxQm.:16338:0:99999:7:::
bin:*:15615:0:99999:7:::
要點: root(第一個字段):用戶名
$6$jmM2rFzPCFbmqBkf$oz3AUooR3qaV5uXU67HcXlYiE3hNf0sSsunk1eBTDPrGUOM1xYCyesGoj.ZLTIzdiXEdrnnqNyC5g8SsRnxQm.(第2個字段):經過加密的密碼
16338(第3個字段):最近更改密碼的時間,從1970/1/1 到上次修改密碼的天數
0(第4個字段):禁止修改密碼的天數,從1970/1/1開始,多少天內不能修改密碼
99999(第5個字段):密碼的有效期,從1970/1/1開始,過了多少天必須修改密碼
7(第6個字段):密碼到期前開始提醒用戶修改密碼的天數
(第7個字段):密碼過期后的寬限天數
(第8個字段):從1970/1/1開始,到用戶被禁的天數,默認為空
(第9個字段):保留,未使用
3./etc/group & /etc/shadow 與/etc/passwd & /etc/gshadow 類似.其中/etc/group 中存在本組成員用戶列表,可以查看加入這個組的所有用戶
二,用戶和用戶組管理
主要涉及文件有:/etc/skel目錄 /etc/login.defs /etc/default/useradd
1./etc/skel
存放模板文件的目錄,所謂模板,就是新用戶創建后會自動添加到該用戶的家目錄下的文件(一般是隱藏文件)
[root@localhost ~]# ls -al /etc/skel/
total 64
drwxr-xr-x 3 root root 4096 Apr 30 17:20 .
drwxr-xr-x 91 root root 12288 May 2 10:01 ..
-rw-r--r-- 1 root root 33 May 13 2011 .bash_logout
-rw-r--r-- 1 root root 176 May 13 2011 .bash_profile
-rw-r--r-- 1 root root 124 May 13 2011 .bashrc
-rw-r--r-- 1 root root 515 Apr 7 2011 .emacs
drwxr-xr-x 4 root root 4096 Apr 30 17:20 .mozilla
2./etc/login/defs
[root@localhost ~]# cat /etc/login.defs
# *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 #創建用戶時,要在目錄/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 500 #最小UID為500,也就是說添加用戶時,UID是從500開始的;
UID_MAX 60000 #最大UID為60000;
#
# Min/max values for automatic gid selection in groupadd
#
GID_MIN 500 #GID依然是從500開始;同上面用戶的情況;
GID_MAX 60000
#
# 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 #是否創建用戶家目錄,默認要求創建;可用-m參數來控制;
# The permission mask is initialized to this value. If not specified,
# the permission mask will be initialized to 022.
UMASK 077
# This enables userdel to remove user groups if no members exist.
#
USERGROUPS_ENAB yes #刪除用戶同時刪除用戶組
# Use MD5 or DES to encrypt password? Red Hat use MD5 by default.
MD5_CRYPT_ENAB yes #MD5密碼加密
3./etc/default/useradd
[root@localhost ~]# cat /etc/default/useradd
# useradd defaults file
GROUP=100
HOME=/home #把用戶的家目錄建在/home中
INACTIVE=-1 #是否啟動賬號過期停權,-1表示不啟用
EXPIRE= #賬號終止日期,不設置表示不啟用
SHELL=/bin/bash #新用戶默認所用的shell類型
SKEL=/etc/skel #配置新用戶家目錄的默認文件存放路徑。前文提到的/etc/skell,就是配在這里生效的,即當我們用useradd添加時,用戶家目錄的文件,都是從這里配置的目錄中復制過去的。
CREATE_MAIL_SPOOL=yes #創建mail文件