歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Unix知識 >> Unix教程 >> 用戶和基本的帳戶管理

用戶和基本的帳戶管理

日期:2017/2/27 17:39:44   编辑:Unix教程
修改帳戶   在UNIX® 的處理用戶帳戶的環境中有很多不同的命令可用. 最普通的命令如下,接下來是詳細使用它們的例子。

命令 摘要 adduser(8) 在命令行添加新用戶. rmuser(8) 在命令行刪除用戶. chpass(1) 一個靈活的用於修改用戶數據庫信息的工具. passwd(1) 一個用於修改用戶口令的簡單的命令行工具. pw(8) 一個強大靈活修改用戶帳戶的工具.

13.6.1 添加用戶   adduser(8) 是一個簡單的添加新用戶的命令. 它為用戶創建 passwd 和 group 文件。 它也為新用戶創建一個主目錄,它拷貝一個默認的配置文件 (“dotfiles”) 從 /usr/share/skel 這個目錄,然後給新用戶發送一封帶歡迎信息的郵件。   在FreeBSD 5.0版本, adduser(8)命令從Perl腳本改寫為shell腳本,起包裝pw(8)的作用,所以它的用法在 FreeBSD 4.X 上和 FreeBSD 5.X 上略有不同。   建立初始化配置文件, 使用 adduser -s -config_create. [1] 接下來, 我們配置 adduser(8) 的默認設置, 並建立第一個普通用戶帳戶, 因為將 root 用於日常使用會帶來很多潛在問題。 例 13-1. 配置 adduser 和添加一個新用戶,在FreeBSD 4.X版本 # adduser -v Use option ``-silent'' if you don't want to see all warnings and questions. Check /etc/shells Check /etc/master.passwd Check /etc/group Enter your default shell: csh date no sh tcsh zsh [sh]: zsh Your default shell is: zsh -> /usr/local/bin/zsh Enter your default HOME partition: [/home]: Copy dotfiles from: /usr/share/skel no [/usr/share/skel]: Send message from file: /etc/adduser.message no [/etc/adduser.message]: no Do not send message Use passwords (y/n) [y]: y Write your changes to /etc/adduser.conf? (y/n) [n]: y Ok, let's go. Don't worry about mistakes. I will give you the chance later to correct any input. Enter username [a-z0-9_-]: jru Enter full name []: J. Random User Enter shell csh date no sh tcsh zsh [zsh]: Enter home directory (full path) [/home/jru]: Uid [1001]: Enter login class: default []: Login group jru [jru]: Login group is ``jru''. Invite jru into other groups: guest no [no]: wheel Enter password []: Enter password again []: Name: jru Password: **** Fullname: J. Random User Uid: 1001 Gid: 1001 (jru) Class: Groups: jru wheel HOME: /home/jru Shell: /usr/local/bin/zsh OK? (y/n) [y]: y Added user ``jru'' Copy files from /usr/share/skel to /home/jru Add another user? (y/n) [y]: n Goodbye! #   總體而言,我們把默認的shell設置成 zsh (一個可以在 Ports Collection 找到的 shell), 關閉歡迎郵件。 然後保存配置, 接著創建一個名為 jru的帳戶,並且確信 jru 在 wheel 組裡 (這樣它就能夠通過 su(1) 轉變為 root。) 注意: 輸入的口令不會被回顯, 也不會顯示星號。 請確保不要誤輸口令。 注意: 從現在起, 使用 adduser(8) 不再需要改變默認設置。 如果您要求改變默認設置, 先退出程序, 然後使用 -s 選項。 例 13-2. 添加一個新用戶在FreeBSD 5.X版本 # adduser Username: jru Full name: J. Random User Uid (Leave empty for default): Login group [jru]: Login group is jru. Invite jru into other groups? []: wheel Login class [default]: Shell (sh csh tcsh zsh nologin) [sh]: zsh Home directory [/home/jru]: Use password-based authentication? [yes]: Use an empty password? (yes/no) [no]: Use a random password? (yes/no) [no]: Enter password: Enter password again: Lock out the account after creation? [no]: Username : jru Password : **** Full Name : J. Random User Uid : 1001 Class : Groups : jru wheel Home : /home/jru Shell : /usr/local/bin/zsh Locked : no OK? (yes/no): yes adduser: INFO: Successfully added (jru) to the user database. Add another user? (yes/no): no Goodbye! # 13.6.2 刪除用戶   您可以使用rmuser(8) 從系統中完全刪除一個用戶. rmuser(8) 執行如下步驟: 1. 刪除用戶的 crontab(1) 記錄 (如果有的話). 2. 刪除屬於用戶的at(1) 工作. 3. 殺掉屬於用戶的所有進程. 4. 刪除本地口令文件中的用戶. 5. 刪除用戶的主目錄 (如果他有自己的主目錄). 6. 刪除來自 /var/mail屬於用戶的郵件. 7. 刪除所有諸如 /tmp的臨時文件存儲區中的文件. 8. 最後, 刪除 /etc/group中所有屬於組的該用戶名. 注意: 如果一個組變成空,而組名和用戶名一樣,組將被刪除. adduser(8)命令建立每個用戶唯一的組.   rmuser(8) 不能用來刪除超級用戶的帳戶, 因為那樣做是對系統極大的破壞.   默認情況下, 使用交互模式, 這樣能夠讓您清楚的知道您在做什麼. 例 13-3. 刪除用戶 交互模式下的帳戶刪除 # rmuser jru Matching password entry: jru:*:1001:1001::0:0:J. Random User:/home/jru:/usr/local/bin/zsh Is this the entry you wish to remove? y Remove user's home directory (/home/jru)? y Updating password file, updating databases, done. Updating group file: trusted (removing group jru -- personal group is empty) done. Removing user's incoming mail file /var/mail/jru: done. Removing files belonging to jru from /tmp: done. Removing files belonging to jru from /var/tmp: done. Removing files belonging to jru from /var/tmp/vi.recover: done. # 13.6.3 chpass   chpass(1) 可以改變用戶的口令, shells, 和包括個人信息在內的數據庫信息.   只有系統管理員, 即超級用戶, 才可以用 chpass(1) 改變其他用戶口令和信息。   除了可選擇的用戶名, 不需要任何選項, chpass(1) 將顯示一個包含用戶信息的編輯器. 可以試圖改變用戶在數據庫中的信息. 注意: 在 FreeBSD 5.X版本, 編輯退出後,您應該索要您的口令,如果您不是超級用戶的話. 例 13-4. 以超級用戶交互執行 chpass 命令 #Changing user database information for jru. Login: jru Password: * Uid [#]: 1001 Gid [# or name]: 1001 Change [month day year]: Expire [month day year]: Class: Home directory: /home/jru Shell: /usr/local/bin/zsh Full Name: J. Random User Office Location: Office Phone: Home Phone: Other information:   普通用戶只能改變他們自己很少的一部分信息. 例 13-5. 以普通用戶交互執行 chpass 命令 #Changing user database information for jru. Shell: /usr/local/bin/zsh Full Name: J. Random User Office Location: Office Phone: Home Phone: Other information: 注意: chfn(1) 和 chsh(1) 只是到 chpass(1) 的符號連接,類似地, ypchpass(1), ypchfn(1) 以及 ypchsh(1) 也是這樣。 NIS 是自動支持的, 不一定要在命令前指定 yp。如果這讓您有點不太明白,不必擔心, NIS 將在 第 24 章 介紹。 13.6.4 passwd命令   passwd(1) 是改變您自己作為一個普通用戶口令或者作為超級用戶口令常用的方法. 注意: 用戶改變口令前必須鍵入原來的口令, 防止用戶離開終端時非授權的用戶進入改變合法用戶的口令。 例 13-6. 改變您的口令 % passwd Changing local password for jru. Old password: New password: Retype new password: passwd: updating the database... passwd: done 例 13-7. 改變其他用戶的口令同超級用戶的一樣 # passwd jru Changing local password for jru. New password: Retype new password: passwd: updating the database... passwd: done 注意: 就象 chpass(1)一樣, yppasswd(1) 只是一個到 passwd(1)的連接, 所以NIS用任何一個命令都可以正常工作. 13.6.5 pw命令   pw(8) 是一個用來創建、刪除、修改、顯示用戶和組的命令行工具。它還有系統用戶和組文件編輯器的功能。 pw(8) 有一個非常強大的命令行選項設置, 但新用戶可能會覺得它比這裡講的其它命令要復雜很多。 備注

[1] 選項-sadduser(8) 是。當我們想要改變默認設置可以使用-v選項

Copyright © Linux教程網 All Rights Reserved