在Unix系統(tǒng)上的賬戶有三種類型:
Root 賬號: 這也被稱為超級用戶,并有完整的和不受約束的控制系統(tǒng)。一個超級用戶可以運行任何命令,沒有任何限制。該用戶應承擔作為一個系統(tǒng)管理員。
System 賬號: 系統(tǒng)帳戶是那些需要特定系統(tǒng)組件,例如電子郵件帳戶和sshd的賬戶的操作。這些賬戶通常需要在您的系統(tǒng)上的一些特定功能,任何修改系統(tǒng)可能會受到不好的影響。
User 賬號: 用戶帳戶提供交互式訪問系統(tǒng)的用戶和用戶組。一般使用者通常分配給這些帳戶,通常有有限的訪問關鍵系統(tǒng)文件和目錄。
UNIX支持組帳戶的概念邏輯分組多個賬戶。每個帳戶將任何組帳戶的一部分。 Unix群組中起著重要的作用,在處理文件的權限和流程管理。
有三個主要的用戶管理文件:
/etc/passwd: 保持用戶帳戶和密碼信息。這個文件包含了大多數(shù)的Unix系統(tǒng)上的賬戶信息。
/etc/shadow: 相應的帳戶保存加密口令。并非所有的系統(tǒng)支持此文件。
/etc/group: 此文件包含每個帳戶的組信息。
/etc/gshadow: 此文件包含安全組的帳戶信息。
檢查上述所有文件使用cat命令。
以下是大多數(shù)Unix系統(tǒng)上可用來創(chuàng)建和管理帳戶和組的命令:
| 命令 | 描述 |
|---|---|
| useradd | Adds accounts to the system. |
| usermod | Modifies account attributes. |
| userdel | Deletes accounts from the system. |
| groupadd | Adds groups to the system. |
| groupmod | Modifies group attributes. |
| groupdel | Removes groups from the system. |
您可以使用聯(lián)機幫助幫助這里提到的每個命令的語法檢查完成。
您需要創(chuàng)建組,然后才能再創(chuàng)建任何帳戶,系統(tǒng)中必須使用現(xiàn)有組。你將不得不在 /etc/groups文件中列出的所有組。
所有默認組將系統(tǒng)帳戶的特定群體,它是不推薦使用普通帳戶。所以語法來創(chuàng)建一個新的帳戶:
groupadd [-g gid [-o]] [-r] [-f] groupname
下面是詳細的參數(shù):
| 選項 | 描述 |
|---|---|
| -g GID | The numerical value of the group's ID. |
| -o | This option permits to add group with non-unique GID |
| -r | This flag instructs groupadd to add a system account |
| -f | This option causes to just exit with success status if the specified group already exists. With -g, if specified GID already exists, other (unique) GID is chosen |
| groupname | Actaul group name to be created. |
如果你不指定任何參數(shù),那么系統(tǒng)將使用默認值。
以下示例將創(chuàng)建開發(fā)組的默認值,這是非常可以接受的大多數(shù)管理員。
$ groupadd developers
要修改組,使用groupmod語法:
$ groupmod -n new_modified_group_name old_group_name
要改變developers_2 組的名稱到開發(fā)組,輸入:
$ groupmod -n developer developer_2
這里顯示如何改變GID為545:
$ groupmod -g 545 developer
要刪除現(xiàn)有的組,所有你需要的是一個命令groupdel命令和組名。要刪除的 financial 組,該命令是:
$ groupdel developer
這將刪除組,沒有任何與該組相關的文件。這些文件是由他們的所有者仍然可以訪問。
讓我們來看看如何在你的Unix系統(tǒng)上創(chuàng)建一個新的帳戶。以下是語法來創(chuàng)建用戶帳戶:
useradd -d homedir -g groupname -m -s shell -u userid accountname
下面是詳細的參數(shù):
| Option | 描述 |
|---|---|
| -d homedir | Specifies home directory for the account. |
| -g groupname | Specifies a group account for this account. |
| -m | Creates the home directory if it doesn't exist. |
| -s shell | Specifies the default shell for this account. |
| -u userid | You can specify a user id for this account. |
| accountname | Actual account name to be created |
如果你不指定任何參數(shù),那么系統(tǒng)將使用默認值。useradd命令修改了 /etc/passwd, /etc/shadow, 和 /etc/group文件,并創(chuàng)建一個主目錄。
下面的例子將創(chuàng)建一個帳戶 mcmohd 其主目錄設置到 /home/mcmohd 和開發(fā)組。該用戶將有Korn Shell的分配給它。
$ useradd -d /home/mcmohd -g developers -s /bin/ksh mcmohd
發(fā)出上述命令前,請確保你已經(jīng)有開發(fā)組使用groupadd的命令創(chuàng)建。
一旦創(chuàng)建一個帳戶,你可以設置其密碼,使用passwd命令如下:
$ passwd mcmohd20 Changing password for user mcmohd20. New UNIX password: Retype new UNIX password: passwd: all authentication tokens updated successfully.
當你輸入 passwd accountname,它給你提供的密碼你是超級用戶,否則,你就可以改變你的密碼使用相同的命令,但沒有指定帳戶名選項來改變。
通過usermod命令使您可以更改現(xiàn)有的帳戶,在命令行。它使用相同的參數(shù),useradd命令,加上-l參數(shù),它允許您更改帳戶名。
舉例來說,,更改帳戶名稱 mcmohd 到 mcmohd20,并相應地改變主目錄,你會需要發(fā)出以下命令:
$ usermod -d /home/mcmohd20 -m -l mcmohd mcmohd20
userdel命令可以用來刪除現(xiàn)有用戶。這是一個非常危險的命令,如果不小心使用。
只有一個參數(shù)或選項可用于命令:.r,刪除帳戶的主目錄和郵件文件。
例如,刪除帳戶mcmohd20,您將需要發(fā)出以下命令:
$ userdel -r mcmohd20
如果你想保持她的主目錄備份的目的,省略-r選項。您可以刪除的主目錄,在以后的時間。