<div class="artical-content-bak main-content editor-side-new">
<div class="con editor-preview-side" id="result">
<p><span style="font-size:20px;"><strong>一、用户管理命令</strong></span><br></p>
<p> 相关命令:useradd、userdel、usermod、passwd、chsh、chfn、finger、id、chage、newgrp</p>
<p><span style="font-size:18px;"><strong>1、useradd命令</strong></span></p>
<p> 1)功能:<br></p>
<pre class="brush:bash;toolbar:false">[root@localhost /]# whatis useradd
useradd (8) - 创建一个新用户或更新默认新用户信息</pre>
<p> 2)常用选项:<br></p>
<table width="994"><tbody><tr class="ue-table-interlace-color-single firstRow"><td align="center" style="border-color:rgb(221,221,221);" width="74"><strong>选项</strong></td><td align="center" style="border-color:rgb(221,221,221);" width="919"><strong>含义</strong></td></tr><tr class="ue-table-interlace-color-double"><td style="border-color:rgb(221,221,221);" width="74">-g</td><td style="border-color:rgb(221,221,221);" width="919">指定所属组</td></tr><tr class="ue-table-interlace-color-single"><td style="border-color:rgb(221,221,221);" width="74">-u</td><td style="border-color:rgb(221,221,221);" width="919">指定UID号</td></tr><tr class="ue-table-interlace-color-double"><td style="border-color:rgb(221,221,221);" width="74">-s</td><td style="border-color:rgb(221,221,221);" width="919">指定登录的shell</td></tr><tr class="ue-table-interlace-color-single"><td style="border-color:rgb(221,221,221);" width="74">-d</td><td style="border-color:rgb(221,221,221);" width="919">指定家目录</td></tr><tr class="ue-table-interlace-color-double"><td style="border-color:rgb(221,221,221);" width="74">-G</td><td style="border-color:rgb(221,221,221);" width="919">指定属于多个组(附属组)</td></tr><tr class="ue-table-interlace-color-single"><td style="border-color:rgb(221,221,221);" width="74">-M</td><td style="border-color:rgb(221,221,221);" width="919">指定不创建家目录</td></tr><tr class="ue-table-interlace-color-double"><td style="border-color:rgb(221,221,221);" width="74">-m</td><td style="border-color:rgb(221,221,221);" width="919">指定创建家目录</td></tr><tr class="ue-table-interlace-color-single"><td style="border-color:rgb(221,221,221);" width="74">-e</td><td style="border-color:rgb(221,221,221);" width="919">账号终止日期,日期指定的格式为MM/DD/YY</td></tr><tr class="ue-table-interlace-color-double"><td style="border-color:rgb(221,221,221);" width="74">-f</td><td style="border-color:rgb(221,221,221);" width="919">账号过期几日后永久停权。当值为0时账号立即停权,为-1时则关闭此功能,预设值为-1。</td></tr><tr class="ue-table-interlace-color-single"><td colspan="1" rowspan="1" style="border-color:rgb(221,221,221);" width="74">-c</td><td colspan="1" rowspan="1" style="border-color:rgb(221,221,221);" width="919">注释</td></tr><tr class="ue-table-interlace-color-double"><td colspan="1" rowspan="1" style="border-left-color:rgb(221,221,221);border-top-color:rgb(221,221,221);">-h</td><td colspan="1" rowspan="1" style="border-left-color:rgb(221,221,221);border-top-color:rgb(221,221,221);">显示此命令的帮助信息</td></tr></tbody></table>
<p> 3)实例:<br></p>
<p> 创建一个名为oldboy的用户,不创建家目录,不登录shell,指定UID号为8888,注释为virtual user。<br></p>
<pre class="brush:bash;toolbar:false">[root@localhost /]# useradd -c "virtual user" -M -s /sbin/nologin -u 8888 oldboy
[root@localhost /]# grep oldboy /etc/passwd
oldboy:x:8888:8888:virtual user:/home/oldboy:/sbin/nologin
[root@localhost /]# ls /home/
tom user</pre>
<p><strong style="font-size:18px;">2、userdel命令</strong></p>
<p> 1)功能:<br></p>
<pre class="brush:bash;toolbar:false">[root@localhost /]# whatis userdel
userdel (8) - 删除用户账户和相关文件</pre>
<p> 2)常用选项:<br></p>
<table><tbody><tr class="ue-table-interlace-color-single firstRow"><td align="center" style="border-color:rgb(221,221,221);" width="74"><strong>选项</strong></td><td align="center" style="border-color:rgb(221,221,221);" width="919"><strong>含义</strong></td></tr><tr class="ue-table-interlace-color-double"><td width="484">-r</td><td width="484">删除主目录和邮件池</td></tr><tr class="ue-table-interlace-color-single"><td width="484">-f</td><td width="484">强制删除,即使登录中</td></tr><tr class="ue-table-interlace-color-double"><td width="484">-h</td><td width="484">查看此帮助信息</td></tr></tbody></table>
<p> 3)实例:<br></p>
<p> 删除admin用户,并同时删除家目录。<br></p>
<pre class="brush:bash;toolbar:false">[root@localhost /]# grep admin /etc/passwd
admin:x:8889:8889::/home/admin:/bin/bash
[root@localhost /]# ls /home/
admin tom user
[root@localhost /]# userdel -r admin
[root@localhost /]# grep admin /etc/passwd
[root@localhost /]# ls /home/
tom user</pre>
<p><strong style="font-size:18px;">3、usermod命令</strong></p>
<p> 1)功能:<br></p>
<p> 修改账户属性<br></p>
<pre class="brush:bash;toolbar:false">[root@localhost /]# whatis usermod
usermod (8) - 修改一个用户账 |
|