系統管理員主要的任務之一就是使用者管理:將新使用者加入系統內,以及當他們離開時 把帳號除去。在 FreeBSD 的機器上,你有 adduser、 addgroup、rmuser以及 chsh 等工具能幫助你完成這些管理的工作。
在標準 Unix 系統內,使用者管理的兩個主要關鍵檔案是 /etc/passwd 及 /etc/group。在 Unix 系統中除了使用者個人外,還有一 個「群組」的觀念,每一個使用者一定屬於系統中的一個群組(但不限 一個)。
以下就先以實例說明相關檔案:
h090120:bkNybeFcy7dHA:4004:103::0:0:陳彥銘:/home/dp/h090120:/usr/local/bin/tcsh ^^^^^^^ ^^^^^^^^^^^^^ ^^^^ ^^^ ^ ^ ^^^^^^ ^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^ ID 密碼(經過加密) UID GID 真實資料 根目錄 shell請參考 adduser指令以了解增加新使用者的方法。
wheel:*:0:root,h090120 staff:*:20:root,apache,h090120 special:*:100:h090101 is:*:101:h090102,h090105,h090106,h090107 sm:*:102:h090103,h090110,h090111,h090112 dp:*:103:h090104,h09011d,h09011e,h090120請參考 addgroup 指令了解增加新群組的方法。
adduser 是管理者用來增加系統使用者的指令,前面提過每個使用者所具備的資料, 那些資料在使用 adduser 指令時都會要求系統管理者輸入。因此系統管理者在增加新使用 者資料前必須先進行規劃後再行輸入資料,以避免不必要的資料更動。現以實例說明如下:
#adduser Use option ``-verbose'' if you want see more warnings & questions or try to repair bugs. Enter username [A-Za-z0-9_]:h090101 Enter full name []: 陳彥銘 Enter shell bash csh date no sh tcsh zsh [tcsh]: Uid [1001]: Login group h090101 [h090101]: special Login group is ``special''. Invite h090101 into other groups: guest no [no]: Enter password []: Enter password again []: Name: h090101 Password: **** Fullname: 陳彥銘 Uid: 1001 Gid: 100 (special) Groups: special HOME: /home/h090101 Shell: /usr/local/bin/tcsh OK? (y/n) [y]: Added user ``h090101'' Add another user? (y/n) [y]:
如此即完成使用者個人資料的設定了。可以看看 /etc/passwd 的內容以確定新使用者的資料正確。
addgroup 的功用有二,一是增加系統內新的工作群組,二是替群組增加新的使用 者。因此也須事先作好規劃。以下為實例說明:
1. 新增一個叫 special 的群組,其 gid 是 100,內含一個使用者為 h090101。 #addgroup -g 100 special h090101 或是 2. 增加 h090101 到 special 群組中。 #addgroup special h090101
如此即大功告成,可以看 /etc/group 檔案內容了解情況。
#rmuser Enter login name for user to remove: h090101 Matching password entry: h090101:IJRCcK5vNH1Pk:1001:100::0:0:陳彥銘:/home/h090101:/usr/local/bin/tcsh Is this the entry you wish to remove? y Remove user's home directory (/home/h090101)? y Updating password file, updating databases, done. Updating group file: done. Removing user's home directory (/home/h090101): done.
如此就把 h090101 這個使用者的資料給刪除掉了。 關於廢除使用者資料的步驟請參考「使用者帳號申請/廢除表」及其流程。
root(ttyp2)@nic{/etc}[9:02]#chsh
#Changing user database information for root.
Login: h090120
Password: IJRCcK5vNH1Pk
Uid [#]: 1001
Gid [# or name]: 100
Change [month day year]:
Expire [month day year]: 06 13 98
Class:
Home directory: /home/dp/h090120
Shell: /bin/tcsh
Full Name: 陳彥銘
Location:
Office Phone:
Home Phone:
在此可以修改任何使用者的參數。修改完後存檔即完成手續。若以管理者身份執行,在 chsh 後面加上使用者的帳號名稱就可以更改此使用者的資料了。