Linux的使用者和組之詳解使用者和組的分類

來源:互聯網
上載者:User

Linux的使用者和組之詳解使用者和組的分類 一、Linux使用者分類 Linux具有三種使用者:超級管理員root:具有最高許可權,UID=0  GID=0系統使用者(System Account):主要服務於應用,維護系統運行,不能登入。普通使用者(login-Account):登入使用者 root和普通使用者都比較熟悉,稍微介紹下系統使用者。 典型系統使用者:bin:x:1:1:bin:/bin:/sbin/nologindaemon:x:2:2:daemon:/sbin:/sbin/nologinadm:x:3:4:adm:/var/adm:/sbin/nologinshutdown:x:6:0:shutdown:/sbin:/sbin/shutdownhalt:x:7:0:halt:/sbin:/sbin/haltmail:x:8:12:mail:/var/spool/mail:/sbin/nologinuucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologinoperator:x:11:0:operator:/root:/sbin/nologingames:x:12:100:games:/usr/games:/sbin/nologingopher:x:13:30:gopher:/var/gopher:/sbin/nologinftp:x:14:50:FTP User:/var/ftp:/sbin/nologinnobody:x:99:99:Nobody:/:/sbin/nologin 不禁會問,為什麼會有系統使用者? Linux系統的大部分許可權和安全的管理依賴於對於檔案許可權(讀、寫、執行)的管理,而使用者是能夠擷取系統資源的許可權的集合,檔案許可權的擁有者為使用者; 當應用需要訪問/操作/擁有系統的資源時,Linux就通過使用者來控制/實現,這些使用者就是系統使用者。例如:sys:The sys user owns the default mounting point for the Distributed File Service (DFS) cache, which must exist before you can install or configure DFS on a client.     The /usr/sys directory can also store installation images.ftp:Used for anonymous FTP access.nobody:Owns no files and is sometimes used as a default user for unprivileged operations.  二、Linux組  PS:此處的使用者全是指普通使用者,即登入使用者。 組和使用者的關係Linux系統以組Group方式系統管理使用者,使用者和組的對應關係為多對多,即某個使用者可加入/屬於一個或多個組,某個組可以有0個、1個或多個使用者。 組的分類從使用者的角度,分為主組和附屬組。主組:也被稱為primary group、first group或initial login group,使用者的預設組,使用者的gid所標識的組。附屬組:也被稱為Secondary group或supplementary group,使用者的附加組。 通過id命令可查看目前使用者的主組和附屬組 [root@localhost ~]# id rootuid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel) [root@localhost ~]# id gguid=503(gg) gid=503(gg) groups=503(gg) [root@localhost ~]# id mmuid=502(mm) gid=500(jww) groups=500(jww) gid標識主組,groups表示使用者所屬的全部組(主組和附屬組) 1. 使用者必須有且只能有一個主組,可以有0個、1個或多個附屬組,就如我們一定會有一個用來安家的房子(類同主組),還可以有n個用於投資或其他打算的房子(附屬組)。 2. 主組也為預設組,當使用者own某個檔案或目錄時,預設該檔案或目錄的group owner為該使用者的主組(當然,可以通過chgrp修改group owner)。 3. 在/etc/passwd檔案中,記錄行第四個欄位為gid,即使用者的主組id。 4. 在/etc/group檔案中,記錄行第四個欄位為組的成員,不顯示將該組作為主組的群組成員,只顯示將該組作為附屬組的群組成員,因此,/etc/group的記錄行的第四個欄位沒有完整地列出該組的全部成員。 5. 當通過useradd命令建立新使用者時,可以通過-g參數指定已存在的某個組為其主組,若沒有使用-g參數,則系統自動建立名稱和使用者名稱相同的組作為該使用者的主組(前提是variable in /etc/login.defs的USERGROUPS_ENAB屬性值為yes),如命令手冊的useradd關於-g參數的描述所示: -g, --gid GROUP     The group name or number of the user′s initial login group. The     group name must exist. A group number must refer to an already     existing group.     If not specified, the bahavior of useradd will depend on the     USERGROUPS_ENAB variable in /etc/login.defs. If this variable is     set to yes (or -U/--user-group is specified on the command line), a     group will be created for the user, with the same name as her     loginname. If the variable is set to no (or -N/--no-user-group is     specified on the command line), useradd will set the primary group     of the new user to the value specified by the GROUP variable in     /etc/default/useradd, or 100 by default. 另外,可通過usermod -g 將普通使用者的主組/gid設定為系統中存在的任意某個組(永久性);也可以通過newgrp暫時性變更目前使用者的主組/gid(只對於當前login session有效,非永久性)。通過usermod -G 設定普通使用者的附屬組。 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.