uTools-Manuals/docs/linux/passwd.html
2019-04-21 11:50:48 +08:00

77 lines
4.2 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<h1 id="passwd">passwd</h1>
<p>用于让用户可以更改自己的密码</p>
<h2 id="补充说明">补充说明</h2>
<p><strong>passwd命令</strong> 用于设置用户的认证信息,包括用户密码、密码过期时间等。系统管理者则能用它管理系统用户的密码。只有管理者可以指定用户名称,一般用户只能变更自己的密码。</p>
<h3 id="语法">语法</h3>
<pre><code class="language-bash">passwd(选项)(参数)</code></pre>
<h3 id="选项">选项</h3>
<pre><code class="language-bash">-d删除密码仅有系统管理者才能使用
-f强制执行
-k设置只有在密码过期失效后方能更新
-l锁住密码
-s列出密码的相关信息仅有系统管理者才能使用
-u解开已上锁的帐号。</code></pre>
<h3 id="参数">参数</h3>
<p>用户名:需要设置密码的用户名。</p>
<h3 id="知识扩展">知识扩展</h3>
<p>与用户、组账户信息相关的文件</p>
<p>存放用户信息:</p>
<pre><code class="language-bash">/etc/passwd
/etc/shadow</code></pre>
<p>存放组信息:</p>
<pre><code class="language-bash">/etc/group
/etc/gshadow</code></pre>
<p>用户信息文件分析(每项用<code>:</code>隔开)</p>
<pre><code class="language-bash">例如jack:X:503:504:::/home/jack/:/bin/bash
jack  //用户名
X  //口令、密码
503  //用户id0代表root、普通新建用户从500开始
504  //所在组
:  //描述
/home/jack/  //用户主目录
/bin/bash  //用户缺省Shell</code></pre>
<p>组信息文件分析</p>
<pre><code class="language-bash">例如jack:$!$:???:13801:0:99999:7:*:*:
jack  //组名
$!$  //被加密的口令
13801  //创建日期与今天相隔的天数
0  //口令最短位数
99999  //用户口令
7  //到7天时提醒
*  //禁用天数
*  //过期天数</code></pre>
<h3 id="实例">实例</h3>
<p>如果是普通用户执行passwd只能修改自己的密码。如果新建用户后要为新用户创建密码则用passwd用户名注意要以root用户的权限来创建。</p>
<pre><code class="language-bash">[root@localhost ~]# passwd linuxde //更改或创建linuxde用户的密码
Changing password for user linuxde.
New UNIX password: //请输入新密码;
Retype new UNIX password: //再输入一次;
passwd: all authentication tokens updated successfully. //成功;</code></pre>
<p>普通用户如果想更改自己的密码直接运行passwd即可比如当前操作的用户是linuxde。</p>
<pre><code class="language-bash">[linuxde@localhost ~]$ passwd
Changing password for user linuxde. //更改linuxde用户的密码
(current) UNIX password: //请输入当前密码;
New UNIX password: //请输入新密码;
Retype new UNIX password: //确认新密码;
passwd: all authentication tokens updated successfully. //更改成功;</code></pre>
<p>比如我们让某个用户不能修改密码,可以用<code>-l</code>选项来锁定:</p>
<pre><code class="language-bash">[root@localhost ~]# passwd -l linuxde //锁定用户linuxde不能更改密码
Locking password for user linuxde.
passwd: Success //锁定成功;
[linuxde@localhost ~]# su linuxde //通过su切换到linuxde用户
[linuxde@localhost ~]$ passwd //linuxde来更改密码
Changing password for user linuxde.
Changing password for linuxde
(current) UNIX password: //输入linuxde的当前密码
passwd: Authentication token manipulation error //失败,不能更改密码;</code></pre>
<p>再来一例:</p>
<pre><code class="language-bash">[root@localhost ~]# passwd -d linuxde //清除linuxde用户密码
Removing password for user linuxde.
passwd: Success //清除成功;
[root@localhost ~]# passwd -S linuxde //查询linuxde用户密码状态
Empty password. //空密码,也就是没有密码;</code></pre>
<p>注意:当我们清除一个用户的密码时,登录时就无需密码,这一点要加以注意。</p>
<!-- Linux命令行搜索引擎https://jaywcjlove.github.io/linux-command/ -->