13.6 更改帳號

UNIX® 的環境之中提供了各式不同的指令管理使用者帳號, 以下為較常使用的指令摘要及更詳細的使用範例。

指令 摘要
adduser(8) 新增使用者。
rmuser(8) 移除使用者。
chpass(1) 更改使用者資料。
passwd(1) 更改使用者密碼。
pw(8) 修改使用者的各種資料。

13.6.1 adduser

adduser(8) 是一支新增使用者的簡單程式。 它會建立資料於系統的 passwdgroup 檔案之中。 同時也會建立使用者的家目錄,從 /usr/share/skel 複製預設的組態檔(“dotfiles”), 並可以選擇性的郵件通知新使用者歡迎訊息。

Example 13-1. 在 FreeBSD 內新增使用者

# 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!
#

Note: 您輸入的密碼並不會回應到螢幕,所以不會以星號顯示 。 請確定您所輸入的密碼無誤。

13.6.2 rmuser

您可以使用 rmuser(8) 來將使用者從系統之中完全移除 rmuser(8) 會執行以下動作:

  1. 移除該使用者的 crontab(1) 資料 (如果存在)。

  2. 移除所有屬於該使用者的 at(1) 工作。

  3. 中止所有該使用者擁有的程序。

  4. 移除系統本機密碼檔中該使用者的資料。

  5. 移除該使用者的家目錄 (如果為該使用者所有)。

  6. 移除 /var/mail 中屬於該使用者的郵件。

  7. 移除暫存空間 (如: /tmp) 中所有屬於該使用者的檔案。

  8. 最後,在 /etc/group 檔內移除該使用者帳號。

    Note: 若該群組已無成員,或者是群組名稱與該使用者名稱相同時, 則群組將會被移除; 此操作會與 adduser(8) 所建立的帳號群組相對應。

rmuser(8) 無法移除系統管理者帳號帳號, 因為這即代表嚴重的破壞行為。

為了確認您的操作,預設採互動模式。

Example 13-2. rmuser 帳號移除

# 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) 可更改使用者資料如: 密碼、Shell及個人資訊。

僅系統管理者即系統管理者帳號可利用 chpass(1) 更改其他使用者的資訊及密碼

除了指定使用者名稱,當不加參數時,chpass(1) 會將使用者資訊顯示於編輯器當中。 並於使用者離開編輯器時更新使用者資訊。

Note: 若您並非系統管理者帳號,在離開編輯器前會詢問您的密碼。

Example 13-3. 系統管理者帳號 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:

一般使用者僅可更改自己的少部份資訊。

Example 13-4. 一般使用者 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:

Note: chfn(1)chsh(1) 即為 chpass(1),也同 ypchpass(1)ypchfn(1)ypchsh(1)。 NIS 支援是自動的,所以無需在指令前加上 yp。 若這會困擾您,請不必擔心,Chapter 27 將函蓋 NIS 的部份的說明。

13.6.4 passwd

passwd(1) 是更改密碼常用的方式,除了超級管理者可更改其他使用者的密碼外 使用者僅能更改自己的密碼。

Note: 為了避免意外或未經同意的修改,在更新密碼前需輸入原密碼。

Example 13-5. 更改您的密碼

% passwd
Changing local password for jru.
Old password:
New password:
Retype new password:
passwd: updating the database...
passwd: done

Example 13-6. 以系統管理者帳號去更改其他使用者的密碼

# passwd jru
Changing local password for jru.
New password:
Retype new password:
passwd: updating the database...
passwd: done

Note: chpass(1)yppasswd(1) 即為 passwd(1),皆支援 NIS。

13.6.5 pw

pw(8) 用來建立、移除、修改及查詢使用者及群組。 其功能即為系統使用者及群組檔案的前端。pw(8) 擁有大量的指令參數 較適合使用於 shell script 中,對新手來說會此指令較其他指令複雜許多。

本文及其他文件,可由此下載:ftp://ftp.FreeBSD.org/pub/FreeBSD/doc/

若有 FreeBSD 方面疑問,請先閱讀 FreeBSD 相關文件,如不能解決的話,再洽詢 <questions@FreeBSD.org>。
關於本文件的問題,請洽詢 <doc@FreeBSD.org>。