1. 程式人生 > 其它 >Linux學習之使用者&使用者組配置檔案

Linux學習之使用者&使用者組配置檔案

一.使用者和使用者組配置檔案主要有四個:/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檔案