FlossDoc: 请协力 GPLv3 的中文翻译工作。

File:/etc/passwd

FlossDoc,自由中文開源知識庫

< File: | etc
Jump to: navigation, search

passwd 記錄了 Unix/Linux 系統上每一個使用者的資訊。由於存放了很多程式需要的使用者資訊如 UID 、Home directory 等,它的檔案權限 (file mode) 一般會設為所有使用者可以讀取 (rw-r--r--) 。如其名稱所指,這檔案原本儲存了已加密的使用者密碼。但後來因為安全問題,現代 Unix/Linux 都使用 shadow password 或其他技術,把使用者密碼儲存在 /etc/shadow 或其他地方。

其格式是很簡單的文字檔,一般可以直接使用任何文字編輯器在此檔案增加一行來為系統新增新的使用者。當然大部份 Unix/Linux 都會提供更佳的工具更安全地修此檔案來新增使用者。

目录

結構與內容

passwd 檔案中的每一列記錄了系統每一個使用者的資料。每一列的格式如下:

username:encrypted-password:UID:GID:comment:home-directory:login-shell

以下是個典型 passwd 檔案的內容:

root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/bin/sh
bin:x:2:2:bin:/bin:/bin/sh
sys:x:3:3:sys:/dev:/bin/sh
sync:x:4:65534:sync:/bin:/bin/sync
games:x:5:60:games:/usr/games:/bin/sh
man:x:6:12:man:/var/cache/man:/bin/sh
lp:x:7:7:lp:/var/spool/lpd:/bin/sh
mail:x:8:8:mail:/var/mail:/bin/sh
www-data:x:33:33:www-data:/var/www:/bin/sh
backup:x:34:34:backup:/var/backups:/bin/sh
list:x:38:38:Mailing List Manager:/var/list:/bin/sh
nobody:x:65534:65534:nobody:/nonexistent:/bin/sh
jrandom:x:1000:1000:J. Random,,,:/home/jrandom:/bin/bash
john:x:1001:1001:John,,,:/home/john:/bin/bash
mary:x:1001:1001:Mary,,,:/home/mary:/bin/bash
peter:x:1001:1001:Peter,,,:/home/peter:/bin/bash

每一列都有七欄資料,欄與欄之間以冒號 (“:”) 分隔。每一欄的用途以下:

  1. 使用者名稱 (Username) - 登入和識別使用者的名稱。一般都建議只使用小階英文字母和數字組合作為使用者名稱,而第一個字元一般需要是英文字母。部份 Unix 容許較寬鬆的命名規則,例如很多 Unix 都容許使用底線等 (“_”) ,Solaris 更容許使用點號 (“.”) 和減號 (“-”)。[1] 不過使用如大階字母和點號 (“.”) 有機會搞亂一些如電郵程式等軟件的運作。[2]
  2. 已加密的密碼 (Encrypted password) - 如其名,這欄原本是存放已加密的使用者密碼。不過因為安全問題,很多 Unix/Linux 都使用 shadow password,令這欄一般只有 “x” 。這表示密碼存放在 /etc/shadow 或其他地方。特別留意如果這欄是空的,表示無需輸入密碼就可以登入這使用者。這在正常系統是絕對不可能出現的。唯一原因就是系統已被人入侵。在 AIX 系統中,這欄絕不會存放密碼,只表示使用者是否有有效的密碼。如果這欄為嘆號 “!”,表示有密碼。星號 “*” 則表示沒有密碼和使用者已被鎖不能登入。[3] FreeBSD 和 HP-UX 則在這欄一般只會有星號 “*” 。[4]
  3. 使用者識別編號 (UID, User identification number) - 系統真正識別使用者的編號。早期的 Unix/Linux 一般只可以 0 至 65535 (216 - 1) 間的數目字,新 Unix/Linux 一般可以處理 32 bit UID。Solaris 最高可以為 2147483647 (231 - 1)。如果兩個或以上的使用者擁相同的 UID ,系統會當相同旳使用者處理。[5]特別留意 UID 為 0 的使用者,表示他有和系統管理員 root 相同的權力。如果發現有 root 以外使用者的 UID 為 0 ,一般表示系統已被人入侵和該使用者是入侵者所設的後門 (back door)。
  4. 首要群組識別編號 (GID, Primary group ID) - 使用者登入時預設使用者群組的識別編號,一般要對應 /etc/group 中的群組資料。
  5. 使用者全名或註解 (Comment or User fullname) - 傳統上存放了使用者的真實姓名和其他附加資訊。附加資訊一般會逗號 (“,”) 分隔開,其意義和次序在不同 Unix 系統可有分別,但一般格式為「使用者全名,辦公室編號,辦公室電話號碼,屋宅電話號碼」,各以逗號 (“,”) 分隔開。這欄亦傳統上叫作 GECOS 或 GCOS 欄,因為早期貝爾實驗室 (Bell Lab) 中的 Unix 系統一般使用 GECOS 作列印 spooling 和其他工作,而這欄就被加入 passwd 檔案存放登入 GECOS 系統需要的 ID。[5][6]
  6. 個人目錄 (User home directory) - 使用者個人目錄 (home directory) 的路徑。
  7. 登入命令解析器 (login shell/command interpreter) - 使用登入時使用的 Shell 命令解析器。

標準使用者

大部份 Unix/Linux 都會建立一些如 bin、daemon、mail、lp、games 和 nobody 等使用者作系統之用。這些系統使用者並不屬於任何一個直正的使用者,而主要代表一些或一類系統軟件或服務。一般系統都會預留開體一部份的 UID 給這些系統使用者 (system user),把它們和一般使用者分開。例如 Debian 和 Ubuntu 系統的 UID 0 至 999 都預留作系統使用者之用,UID 1000 開始才是第一個正常使用者。而 Fedora、RHEL 和 CentOS 等則只用 UID 0 至 499 作系統使用者之用。基過多年的發展,很多固有的系統使用者已沒有直正被使用,但基於歷史和兼容原因,現時仍被保留下來。

UID 0 一般被編排給使用者 root,代表超級使用者,是整個系統最高權力的使用者。留意超級使用者的身份來自於 UID 0,而非使月者名稱 root。任何使用者 UID 為 0 就等同超級使用者。[7]因為歷史和兼容因素,UID 0 一般不會使用 root 以外的使用者名稱。

bin, daemon, adm, lp, sync, shutdown 和 sys 等使用者傳統上用作擁有系統檔案或執行想開系統服務之用。

Debian/Ubuntu 使用者

在 Debian/Ubuntu 系統中,UID 0 至 99 屬全域分配系統使用者。由 Debian 計劃分配,在所有 Debian 系統中每一個 UID 對應相同的群組。 [8] [9]

  • daemon (UID 1) - 一些需要寫入一些檔案的服務程式 (daemon) 會編入此系統使用者,現時主要為 portmap 和 atd 等系統服務和其需要寫入的檔案使用。
  • bin (UID 2)
  • sys (UID 3)
  • sync (UID 4)
  • games (UID 5)
  • man (UID 6)
  • lp (UID 7)- 列印系統使用的系統使用者
  • mail (UID 8) - 電子郵件系統使用的系統使用者
  • news (UID 9) - 新聞組軟件使用的系統使用者
  • uucp (UID 10) - UUCP 系統使用的系統使用者
  • proxy (UID 13)
  • www-data (UID 33)
  • backup (UID 34)
  • list (UID 38)
  • irc (UID 39)
  • gnats (UID 41)
  • nobody (UID 65534)

Fedora/RHEL/CentOS 使用者

[10]

  • bin (UID 1)
  • daemon (UID 2)
  • adm (UID 3)
  • lp (UID 4)
  • sync (UID 5)
  • shutdown (UID 6)
  • halt (UID 7)
  • mail (UID 8)
  • news (UID 9)
  • uucp (UID 10)
  • operator (UID 11)
  • games (UID 12)
  • gopher( UID 13)
  • ftp (UID 14)
  • nobody (UID 99)
  • nfsnobody (UID 65534)

相關工具

  • passwd - 更改使用者密碼
  • useradd - 新增使用者
  • userdel - 刪除使用者
  • usermod - 更改使用資訊
  • chfn - 更改使用者名稱
  • chsh - 更改使用者 shell
  • vipw - 編輯 /etc/passwd 檔案

相關檔案

例子

Jailbreak iOS

#
# 4.3BSD-compatable User Database
#
# Note that this file is not consulted for login.
# It only exisits for compatability with 4.3BSD utilities.
#
# This file is automatically re-written by various system utilities.
# Do not edit this file.  Changes will be lost.
#
nobody:*:-2:-2:Unprivileged User:/var/empty:/usr/bin/false
root:*:0:0:System Administrator:/var/root:/bin/sh
mobile:*:501:501:Mobile User:/var/mobile:/bin/sh
daemon:*:1:1:System Services:/var/root:/usr/bin/false
_wireless:*:25:25:Wireless Services:/var/wireless:/usr/bin/false
_securityd:*:64:64:securityd:/var/empty:/usr/bin/false
_mdnsresponder:*:65:65:mDNSResponder:/var/empty:/usr/bin/false
_sshd:*:75:75:sshd Privilege separation:/var/empty:/usr/bin/false
_unknown:*:99:99:Unknown User:/var/empty:/usr/bin/false

參考資料

  1. Sun Micro (2004-07-28). “Solaris 10 Manpage: passwd(4) - password file”.
  2. FreeBSD (2007-05-08). “FreeBSD 7.1 Manpage: passwd(5) - format of the password file”.
  3. IBM. “AIX Security: Using the /etc/passwd file”. IBM Systems Information Center. Accessed at Oct 8th 2008.
  4. Frisch, AEleen (2002). Essential System Administration. 3rd edition. O'Reilly, Inc. p.223.
  5. 5.0 5.1 Frisch, AEleen (2002). Essential System Administration. 3rd edition. O'Reilly, Inc. p.224.
  6. Wikipedia. “Gecos field”. Accessed at Oct 8th 2008.
  7. Frisch, Æleen (2002) 6.1.6 Standard Unix Users and Groups. Essential System Administration, 3rd Edition. O'Reilly. ISBN 0-596-00343-9
  8. Debian (2010-06-28) 9.2.2 UID and GID classes, Debian Policy Manual, 3.9.0. Debian.
  9. Peña, Javier Fernández-Sanguino and Reelsen, Alexander (2010) 12.1.12.1 Are all system users necessary?, Securing Debian Manual, v3.13. Debian.
  10. Red Hat (2010) 33.3. Standard Users, Red Hat Enterprise Linux 5 Deployment Guide, Edition 4. Red Hat

外部連結

Personal tools