adduser -v You are not root! 哦。看起來這是個需要root權(quán)限的管理工作。讓我們再試一次:
su PassWord:
adduser -v /etc/adduser.conf: No such file or directory 可以看到這是我首次在該系統(tǒng)上使用“adduser”工具;它還沒有一個配置文件。
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: bash csh date no sh tcsh [sh]: tcsh adduser讀取一個含有系統(tǒng)上安裝的所有命令解釋器的路徑的文件/etc/shells;然后顯示用戶可以使用的解釋器。注意,向用戶提供的缺省解釋器是Bourne shell (sh),但我把它改為tcsh。
Your default shell is: tcsh -> /bin/tcsh Enter your default HOME partition: [/home]: Copy dotfiles from: /usr/share/skel no [/usr/share/skel]: 當(dāng)我們建完用戶并在接受了從/usr/share/skel目錄拷貝點(diǎn)文件看到的信息之后,可以去看一下那個目錄里的內(nèi)容。
Send message from file: /etc/adduser.message no [/etc/adduser.message]: Create "/etc/adduser.message"? (y/n) [y]: Use passwords (y/n) [y]: Write your configuration to /etc/adduser.conf? (y/n) [y]: 可以看到adduser在/etc目錄下建立了adduser.message和adduser.conf文件。現(xiàn)在準(zhǔn)備建立我們的用戶:
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_-]: dlavigne Enter full name []: Dru Lavigne Enter shell bash csh date no sh tcsh [tcsh]: Enter home directory (full path) [/home/dlavigne]: Uid [1000]: Enter login class: default []: Login group dlavigne [dlavigne]: Login group is "dlavigne". Invite dlavigne into other groups: guest no [no]: Enter password []: Enter password again []:
Dru Lavigne, your account "dlavigne" was created. Have fun! See also chpass(1), finger(1), passwd(1)
Add anything to default message (y/n) [n]: Send message (y/n) [y]: Copy files from /usr/share/skel to /home/dlavigne Add another user? (y/n) [y]: n Goodbye! 現(xiàn)在我已經(jīng)順利地建立了一個用戶,我將離開超級用戶賬號。讓我們以新用戶身份登錄,看一下他們有些什么東東并描述一下這里的內(nèi)容:
login: dlavigne Password:
pwd /usr/home/dlavigne
ls -la
total 12 drwxr-xr-x 2 dlavigne dlavigne 512 Dec 30 11:21 ./ drwxr-xr-x 4 root wheel 512 Dec 30 10:44 ../ -rw-r--r-- 1 dlavigne dlavigne 628 Dec 30 10:44 .cshrc -rw-r--r-- 1 dlavigne dlavigne 299 Dec 30 10:44 .login -rw-r--r-- 1 dlavigne dlavigne 160 Dec 30 10:44 .login_conf -rw------- 1 dlavigne dlavigne 371 Dec 30 10:44 .mail_aliases -rw-r--r-- 1 dlavigne dlavigne 331 Dec 30 10:44 .mailrc -rw-r--r-- 1 dlavigne dlavigne 722 Dec 30 10:44 .PRofile -rw------- 1 dlavigne dlavigne 276 Dec 30 10:44 .rhosts -rw-r--r-- 1 dlavigne dlavigne 852 Dec 30 10:44 .shrc 你可以看到為用戶建立了一個宿主目錄,里面包含很多以點(diǎn)起首的文件。記得我們使用adduser工具時提到的點(diǎn)文件目錄嗎?讓我們現(xiàn)在來看一下:
ls -l /usr/share/skel
total 10 drwxr-xr-x 2 root wheel 512 Dec 8 11:53 ./ drwxr-xr-x 26 root wheel 512 Nov 20 08:11 ../ -rw-r--r-- 1 root wheel 628 Nov 20 07:01 dot.cshrc -rw-r--r-- 1 root wheel 299 Nov 20 07:01 dot.login -rw-r--r-- 1 root wheel 160 Nov 20 07:01 dot.login_conf -rw------- 1 root wheel 371 Nov 20 07:01 dot.mail_aliases -rw-r--r-- 1 root wheel 331 Nov 20 07:01 dot.mailrc -rw-r--r-- 1 root wheel 722 Nov 20 07:01 dot.profile -rw------- 1 root wheel 276 Nov 20 07:01 dot.rhosts -rw-r--r-- 1 root wheel 852 Nov 20 07:01 dot.shrc 可以看到在我們新用戶的宿主目錄建立的八個文件都是從這個目錄中拷貝的模板文件。另外也可以看到只有超級用戶才可以編輯skel目錄里的文件。例如,如果你希望所有用戶都得到定制過的命令解釋器提示符,那么超級用戶可以修改usr/share/skel/dot.cshrc文件,此文件會在建立賬號時拷貝到所有用戶的宿主目錄中。還有,超級用戶也可以在該目錄中放入他希望用戶得到的任何其它點(diǎn)文件;例如你可以為用戶建立定制好的.xinitrc文件。
現(xiàn)在讓我們看一下adduser工具建立的/etc/adduser.message文件:
more /etc/adduser.message
# # Message file for adduser(8) # comment: "#" # default variables: $name, $fullname, $password # other variables: see /etc/adduser.conf after # line "## DO NOT DELETE THIS LINE!" # $fullname, your account "$name" was created. Have fun! See also chpass(1), finger(1), passwd(1) 讓我們把它和新用戶收到的信息比較一下;我使用mail命令該用戶的郵件信息:
login: dlavigne Password: You have mail.
mail Mail version 8.1 6/6/93. Type ? for help. "/var/mail/dlavigne": 1 message 1 new >N 1 genisis Sat Dec 30 12:24 20/540 "Welcome" & 1 Message 1: From genisis Sat Dec 30 12:24:19 2000 Date: Sat, 30 Dec 2000 12:24:19 -0500 (EST) From: User Genisis To: dlavigne Subject: Welcome
Dru Lavigne, your account "dlavigne" was created. Have fun! See also chpass(1), finger(1), passwd(1)
Add anything to default message (y/n) [n]: 如果我要建立其它賬號并打入y,我會得到以下提示:
Use "." or ^D alone on a file to finish your message 我打入的內(nèi)容都會被加入到缺省的信息中,然后發(fā)給該特定的用戶;但是,這不會覆蓋我原先創(chuàng)建的/etc/adduser.message文件。讓我們來試一下這樣做;我將添加一個稱為“test”的賬號,顯示我們關(guān)心的輸出并“剪掉”其余的:
adduser
<剪掉>
Add anything to default message (y/n) [n]: y Use "." or ^D alone on a line to finish your message. Don't forget that every Friday is pizza day! . Send message (y/n) [y]: y 現(xiàn)在讓我們看一下用戶test的郵件信息是什么樣的:
login: test Password: You have mail.
mail Mail version 8.1 6/6/93. Type ? for help. "/var/mail/test": 1 message 1 new >N 1 genisis Sat Dec 30 12:47 22/567 "Welcome" & 1 Message 1: From genisis Sat Dec 30 12:47:07 2000 Date: Sat, 30 Dec 2000 12:47:07 -0500 (EST) From: User Genisis To: test Subject: Welcome
test, your account "test" was created. Have fun! See also chpass(1), finger(1), passwd(1) Don't forget that every Friday is pizza day! 再看一下新信息是否被加到了模板文件:
more /etc/adduser.message
# # Message file for adduser(8) # comment: "#" # default variables: $name, $fullname, $password # other variables: see /etc/adduser.conf after # line "## DO NOT DELETE THIS LINE!" #
$fullname, your account "$name" was created. Have fun! See also chpass(1), finger(1), passwd(1) 看來只有該用戶收到了附加的信息,這正如我們所期望的。在離開adduser.message文件之前我還想做更多的例子。我想讓用戶在他們的歡迎郵件中收到下面這條附加信息:
If you have any problems, contact the administrator at [email protected] 試一下你自己建立一個賬號并把這行加到他們的信息中;你會看到當(dāng)你以該用戶登錄時,附加行沒有出現(xiàn)在郵件信息中。但是如果你把這行改成:
If you have any problems, contact the administrator at admin/@thiscompany.com 那么用戶就會收到附加信息了。注意,我們必須用/符號避開@符號,以便正確解釋。
最后,讓我們看一下剛才建立的adduser.conf文件:
more /etc/adduser.conf
# /etc/adduser.conf - automatic generated by adduser(8) # # Note: adduser read *and* write this file # You may change values, but don't add new things before the # line "## DO NOT DELETE THIS LINE!" # use password for new users # defaultpasswd = yes | no defaultpasswd = yes
# copy dotfiles from this dir ("/usr/share/skel" or "no") dotdir = "/usr/share/skel"
# send this file to new user # ("/etc/adduser.message" or "no") send_message = "/etc/adduser.message"
# config file for adduser ("/etc/adduser.conf") config = "/etc/adduser.conf"
# logfile ("/var/log/adduser" or "no") logfile = "/var/log/adduser"
# default HOME directory ("/home") home = "/home"
# List of directories where shells located # path = ('/bin', '/usr/bin', '/usr/local/bin') path = ('/bin', '/usr/bin', '/usr/local/bin')
# common shell list, first element has higher priority # shellpref = ('bash', 'tcsh', 'ksh', 'csh', 'sh') shellpref = ('csh', 'sh', 'bash', 'tcsh', 'ksh', 'no', 'date')
# defaultshell if not empty ("bash") defaultshell = "tcsh"
# defaultgroup ('USER' for same as # username or any other valid group) defaultgroup = USER
# defaultclass if not empty defaultclass = ""
# new users get this uid (1000) uid_start = "1000"
## DO NOT DELETE THIS LINE! ## your own variables, see /etc/adduser.message ## end 你可以看到這是個簡單的文件,它包含了對adduser工具提示問題的回答。你看到的新信息只是該文件含有adduser記錄文件的存放位置。如果看一下這個記錄文件,會看到建立賬號時的記錄:
more /var/log/adduser
2000/12/30 12:24:18 dlavigne:*:1000:1000(dlavigne):Dru Lavigne 2000/12/30 12:47:06 test:*:1001:1001(test):test Read more from FreeBSD Basics.