Product SiteDocumentation Site

8.4. 使用者與群組資料庫

The list of users is usually stored in the /etc/passwd file, while the /etc/shadow file stores hashed passwords. Both are text files, in a relatively simple format, which can be read and modified with a text editor. Each user is listed there on a line with several fields separated with a colon (“:”).

8.4.1. 使用者清單:/etc/passwd

/etc/passwd 檔案內的欄位清單:
  • 登入,例如 rhertzog
  • password:就是密碼加密的單向函數 (crypt),使用 DESMD5SHA-256SHA-512。以特別符號 “x” 表示加密後的密碼儲存在/etc/shadow
  • uid:用於辨識個別使用者的不重複數字;
  • gid:使用者主要群組 (Debian 的預設值係為每個使用者建立一個群組) 的不重複號碼;
  • GECOS:通常儲存使用者全名的資料欄;
  • 登入資料夾,用於儲存使用者的個人檔案 (環境變數 $HOME 通常指向此處);
  • 登入時執行的程式。通常是命令解譯器 (shell),若指定為 /bin/false (不做任何事並立即回到控制),則使用者無法登入。

8.4.2. 隱藏與加密的密碼檔:/etc/shadow

The /etc/shadow 檔案含以下的欄位:
  • 登入;
  • 加密的密碼;
  • 管理密碼期限的欄位。

8.4.3. 修改既有的帳號或密碼

The following commands allow modification of the information stored in specific fields of the user databases: passwd permits a regular user to change their password, which in turn, updates the /etc/shadow file; chfn (CHange Full Name), reserved for the super-user (root), modifies the GECOS field. chsh (CHange SHell) allows the user to change their login shell; however, available choices will be limited to those listed in /etc/shells; the administrator, on the other hand, is not bound by this restriction and can set the shell to any program of their choosing.
最後,chage (CHange AGE) 命令允許管理者變更密碼的有效期 (-l 使用者 選項列出現在的設定)。以 passwd -e 使用者 命令強迫密碼失效,要求使用者登錄時變更密碼才能繼續使用。

8.4.4. 帳號禁用

有時需要 “禁用一個帳號” (關閉某使用者),基於紀律考量、調查、或使用者太久未登入。被禁用的帳號表示該使用者不能登入或近用該機器。帳號還在機器內且檔案與資料都未被刪除木;祗是不能使用。以 passwd -l 使用者 (鎖定) 命令就能夠達成。以同樣的方式另個選項 -u (解鎖) 就可恢復該帳號。

8.4.5. 群組清單:/etc/group

群組列在 /etc/group 檔案內,單純的文字資料庫類似 /etc/passwd 檔案,包括以下的欄位:
  • 群組名稱;
  • 密碼 (選項):加入群組會用到 (以 newgrpsg 命令,見專欄 基本 在多個群組工作);
  • gid:不重複的群組辨識碼;
  • 成員清單:屬於此群組的使用者名稱清單,以逗點區隔。
The addgroup and delgroup commands add or delete a group, respectively. The groupmod command modifies a group's information (its gid or identifier). The command gpasswd group changes the password for the group, while the gpasswd -r group command deletes it.