📄 users-modifying.html
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta name="generator" content="HTML Tidy, see www.w3.org" /><title>Modifying Accounts</title><meta name="GENERATOR" content="Modular DocBook HTML Stylesheet Version 1.7" /><link rel="HOME" title="FreeBSD Handbook" href="index.html" /><link rel="UP" title="Users and Basic Account Management" href="users.html" /><link rel="PREVIOUS" title="User Accounts" href="users-user.html" /><link rel="NEXT" title="Limiting Users" href="users-limiting.html" /><link rel="STYLESHEET" type="text/css" href="docbook.css" /></head><body class="SECT1" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#840084"alink="#0000FF"><div class="NAVHEADER"><table summary="Header navigation table" width="100%" border="0" cellpadding="0"cellspacing="0"><tr><th colspan="3" align="center">FreeBSD Handbook</th></tr><tr><td width="10%" align="left" valign="bottom"><a href="users-user.html"accesskey="P">Prev</a></td><td width="80%" align="center" valign="bottom">Chapter 13 Users and Basic AccountManagement</td><td width="10%" align="right" valign="bottom"><a href="users-limiting.html"accesskey="N">Next</a></td></tr></table><hr align="LEFT" width="100%" /></div><div class="SECT1"><h1 class="SECT1"><a id="USERS-MODIFYING" name="USERS-MODIFYING">13.6 ModifyingAccounts</a></h1><p>There are a variety of different commands available in the <spanclass="TRADEMARK">UNIX</span>® environment to manipulate user accounts. The mostcommon commands are summarized below, followed by more detailed examples of theirusage.</p><div class="INFORMALTABLE"><a id="AEN18069" name="AEN18069"></a><table border="0" frame="void" class="CALSTABLE"><col width="1*" /><col width="2*" /><thead><tr><th>Command</th><th>Summary</th></tr></thead><tbody><tr><td><a href="http://www.FreeBSD.org/cgi/man.cgi?query=adduser&sektion=8"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">adduser</span>(8)</span></a></td><td>The recommended command-line application for adding new users.</td></tr><tr><td><a href="http://www.FreeBSD.org/cgi/man.cgi?query=rmuser&sektion=8"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">rmuser</span>(8)</span></a></td><td>The recommended command-line application for removing users.</td></tr><tr><td><a href="http://www.FreeBSD.org/cgi/man.cgi?query=chpass&sektion=1"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">chpass</span>(1)</span></a></td><td>A flexible tool to change user database information.</td></tr><tr><td><a href="http://www.FreeBSD.org/cgi/man.cgi?query=passwd&sektion=1"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">passwd</span>(1)</span></a></td><td>The simple command-line tool to change user passwords.</td></tr><tr><td><a href="http://www.FreeBSD.org/cgi/man.cgi?query=pw&sektion=8"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">pw</span>(8)</span></a></td><td>A powerful and flexible tool to modify all aspects of user accounts.</td></tr></tbody></table></div><div class="SECT2"><h2 class="SECT2"><a id="USERS-ADDUSER" name="USERS-ADDUSER">13.6.1 <ttclass="COMMAND">adduser</tt></a></h2><p><a href="http://www.FreeBSD.org/cgi/man.cgi?query=adduser&sektion=8"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">adduser</span>(8)</span></a> is a simpleprogram for adding new users. It creates entries in the system <ttclass="FILENAME">passwd</tt> and <tt class="FILENAME">group</tt> files. It will alsocreate a home directory for the new user, copy in the default configuration files(``dotfiles'') from <tt class="FILENAME">/usr/share/skel</tt>, and can optionally mailthe new user a welcome message.</p><p>In FreeBSD 5.0, <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=adduser&sektion=8"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">adduser</span>(8)</span></a> wasrewritten from a Perl script to a shell script that acts as wrapper around <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=pw&sektion=8"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">pw</span>(8)</span></a>, so its usage isslightly different on FreeBSD 4.X and FreeBSD 5.X.</p><p>To create the initial configuration file, use <tt class="COMMAND">adduser -s-config_create</tt>. <a id="AEN18139" name="AEN18139" href="#FTN.AEN18139"><spanclass="footnote">[1]</span></a> Next, we configure <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=adduser&sektion=8"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">adduser</span>(8)</span></a> defaults,and create our first user account, since using <tt class="USERNAME">root</tt> for normalusage is evil and nasty.</p><div class="EXAMPLE"><a id="AEN18150" name="AEN18150"></a><p><b>Example 13-1. Configuring <tt class="COMMAND">adduser</tt> and adding a user onFreeBSD 4.X</b></p><pre class="SCREEN"><samp class="PROMPT">#</samp> <kbd class="USERINPUT">adduser -v</kbd>Use option ``-silent'' if you don't want to see all warnings and questions.Check /etc/shellsCheck /etc/master.passwdCheck /etc/groupEnter your default shell: csh date no sh tcsh zsh [sh]: <kbd class="USERINPUT">zsh</kbd>Your default shell is: zsh -> /usr/local/bin/zshEnter 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]: <kbd class="USERINPUT">no</kbd>Do not send messageUse passwords (y/n) [y]: <kbd class="USERINPUT">y</kbd>Write your changes to /etc/adduser.conf? (y/n) [n]: <kbd class="USERINPUT">y</kbd>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_-]: <kbd class="USERINPUT">jru</kbd>Enter full name []: <kbd class="USERINPUT">J. Random User</kbd>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]: <kbd class="USERINPUT">wheel</kbd>Enter password []: Enter password again []: Name: jruPassword: ****Fullname: J. Random UserUid: 1001Gid: 1001 (jru)Class: Groups: jru wheelHOME: /home/jruShell: /usr/local/bin/zshOK? (y/n) [y]: <kbd class="USERINPUT">y</kbd>Added user ``jru''Copy files from /usr/share/skel to /home/jruAdd another user? (y/n) [y]: <kbd class="USERINPUT">n</kbd>Goodbye!<samp class="PROMPT">#</samp></pre></div><p>In summary, we changed the default shell to <b class="APPLICATION">zsh</b> (anadditional shell found in the Ports Collection), and turned off the sending of a welcomemail to added users. We then saved the configuration, created an account for <ttclass="USERNAME">jru</tt>, and made sure <tt class="USERNAME">jru</tt> is in <ttclass="USERNAME">wheel</tt> group (so that she may assume the role of <ttclass="USERNAME">root</tt> with the <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=su&sektion=1"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">su</span>(1)</span></a> command.)</p><div class="NOTE"><blockquote class="NOTE"><p><b>Note:</b> The password you type in is not echoed, nor are asterisks displayed. Makesure you do not mistype the password twice.</p></blockquote></div><div class="NOTE"><blockquote class="NOTE"><p><b>Note:</b> Just use <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=adduser&sektion=8"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">adduser</span>(8)</span></a> withoutarguments from now on, and you will not have to go through changing the defaults. If theprogram asks you to change the defaults, exit the program, and try the <varclass="OPTION">-s</var> option.</p></blockquote></div><div class="EXAMPLE"><a id="AEN18183" name="AEN18183"></a><p><b>Example 13-2. Adding a user on FreeBSD 5.X</b></p><pre class="SCREEN"><samp class="PROMPT">#</samp> <kbd class="USERINPUT">adduser</kbd>Username: <kbd class="USERINPUT">jru</kbd>Full name: <kbd class="USERINPUT">J. Random User</kbd>Uid (Leave empty for default):Login group [jru]:Login group is jru. Invite jru into other groups? []: <kbd class="USERINPUT">wheel</kbd>Login class [default]:Shell (sh csh tcsh zsh nologin) [sh]: <kbd class="USERINPUT">zsh</kbd>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 : jruPassword : ****Full Name : J. Random UserUid : 1001Class :Groups : jru wheelHome : /home/jruShell : /usr/local/bin/zshLocked : noOK? (yes/no): <kbd class="USERINPUT">yes</kbd>adduser: INFO: Successfully added (jru) to the user database.Add another user? (yes/no): <kbd class="USERINPUT">no</kbd>Goodbye!<samp class="PROMPT">#</samp></pre></div></div><div class="SECT2"><h2 class="SECT2"><a id="USERS-RMUSER" name="USERS-RMUSER">13.6.2 <ttclass="COMMAND">rmuser</tt></a></h2><p>You can use <a href="http://www.FreeBSD.org/cgi/man.cgi?query=rmuser&sektion=8"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">rmuser</span>(8)</span></a> tocompletely remove a user from the system. <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=rmuser&sektion=8"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">rmuser</span>(8)</span></a> performs thefollowing steps:</p><div class="PROCEDURE"><ol type="1"><li><p>Removes the user's <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=crontab&sektion=1"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">crontab</span>(1)</span></a> entry (ifany).</p></li><li><p>Removes any <a href="http://www.FreeBSD.org/cgi/man.cgi?query=at&sektion=1"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">at</span>(1)</span></a> jobs belongingto the user.</p></li><li><p>Kills all processes owned by the user.</p></li><li><p>Removes the user from the system's local password file.</p></li>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -