复制代码代码如下:[root@localhost ~]# passwd 注:没有加任何用户,我是用root用户来执行的passwd 表示修改root用户的密码;下面也有提示;
Changing password for user root.
New UNIX password: 注:请输入新密码;
Retype new UNIX password: 注:验证新密码;
passwd: all authentication tokens updated successfully. 注:修改root密码成功;如果是普通用户执行passwd 只能修改自己的密码;
如果新建用户后,要为新用户创建密码,则用 passwd 用户名 ,注意要以root用户的权限来创建;
复制代码代码如下:
[root@localhost ~]# passwd beinan注:更改或创建beinan用户的密码;
Changing password for user beinan.
New UNIX password: 注:请输入新密码;
Retype new UNIX password: 注:再输入一次;
passwd: all authentication tokens updated successfully. 注:成功;普通用户如果想更改自己的密码,直接运行passwd即可;比如当前操作的用户是beinan;
复制代码代码如下:
[beinan@localhost ~]$ passwd
Changing password for user beinan. 注:更改beinan用户的密码;
(current) UNIX password: 注:请输入当前密码;
New UNIX password: 注:请输入新密码;
Retype new UNIX password: 注:确认新密码;
passwd: all authentication tokens updated successfully. 注:更改成功;
2、passwd 几个比较重要的参数;
复制代码代码如下:
[root@localhost beinan]# passwd --help
Usage: passwd [OPTION...] <accountName>
-k, --keep-tokens keep non-expired authentication tokens
注:保留即将过期的用户在期满后能仍能使用;
-d, --delete delete the password for the named account (root only)
注:删除用户密码,仅能以root权限操作;
-l, --lock lock the named account (root only)
注:锁住用户无权更改其密码,仅能通过root权限操作;
-u, --unlock unlock the named account (root only)
注:解除锁定;
-f, --force force operation
注:强制操作;仅root权限才能操作;
-x, --maximum=DAYS maximum password lifetime (root only) 注:两次密码修正的最大天数,后面接数字;仅能root权限操作;
-n, --minimum=DAYS minimum password lifetime (root only) 注:两次密码修改的最小天数,后面接数字,仅能root权限操作;
-w, --warning=DAYS number of days warning users receives before 注:在距多少天提醒用户修改密码;仅能root权限操作;
password expiration (root only)
-i, --inactive=DAYS number of days after password expiration when an 注:在密码过期后多少天,用户被禁掉,仅能以root操作;
account becomes disabled (root only)
-S, --status report password status on the named account (root 注:查询用户的密码状态,仅能root用户操作;
only)
--stdin read new tokens from stdin (root only)比如我们让某个用户不能修改密码,可以用-l 参数来锁定:
复制代码代码如下:
[root@localhost ~]# passwd -l beinan注:锁定用户beinan不能更改密码;
Locking password for user beinan.
passwd: Success 注:锁定成功;
[beinan@localhost ~]# su beinan 注:通过su切换到beinan用户;
[beinan@localhost ~]$ passwd 注:beinan来更改密码;
Changing password for user beinan.
Changing password for beinan
(current) UNIX password: 注:输入beinan的当前密码;
passwd: Authentication token manipulation error 注:失败,不能更改密码;
再来一例:
复制代码代码如下:
[root@localhost ~]# passwd -d beinan注:清除beinan用户密码;
Removing password for user beinan.
passwd: Success 注:清除成功;