[root@host ~]# passwd --help
用法: passwd [选项...] <帐号名称>
-k, --keep-tokens 保持身份验证令牌不过期
-d, --delete 删除已命名帐号的密码(只有根用户才能进行此操作)
-l, --lock 锁定指名帐户的密码(仅限 root 用户)
-u, --unlock 解锁指名账户的密码(仅限 root 用户)
-e, --expire 终止指名帐户的密码(仅限 root 用户)
-f, --force 强制执行操作
-x, --maximum=DAYS 密码的最长有效时限(只有根用户才能进行此操作)
-n, --minimum=DAYS 密码的最短有效时限(只有根用户才能进行此操作)
-w, --warning=DAYS 在密码过期前多少天开始提醒用户(只有根用户才能进行此操作)
-i, --inactive=DAYS 当密码过期后经过多少天该帐号会被禁用(只有根用户才能进行此操作)
-S, --status 报告已命名帐号的密码状态(只有根用户才能进行此操作)
--stdin 从标准输入读取令牌(只有根用户才能进行此操作)
新建test用户,并更改其密码
[root@host ~]# useradd test #新建test用户
[root@host ~]# passwd test
更改用户 test 的密码 。
新的 密码:
无效的密码: 密码少于 8 个字符
重新输入新的 密码:
passwd:所有的身份验证令牌已经成功更新。
passwd --stdin
[root@host ~]# echo "123456" | passwd --stdin test
更改用户 test 的密码 。
passwd:所有的身份验证令牌已经成功更新。
passwd -l 和passwd -u
[root@host ~]# passwd -S test/
passwd:未知的用户名 test/。
[root@host ~]# passwd -S test
test PS 2020-05-06 0 99999 7 -1 (密码已设置,使用 SHA512 算法。)
[root@host ~]# passwd -l test
锁定用户 test 的密码 。
passwd: 操作成功
[root@host ~]# passwd -S test
test LK 2020-05-06 0 99999 7 -1 (密码已被锁定。) #LK 锁定状态
[root@host ~]# passwd -u test
解锁用户 test 的密码。
passwd: 操作成功
[root@host ~]# passwd -S test
test PS 2020-05-06 0 99999 7 -1 (密码已设置,使用 SHA512 算法。)
passwd -e
[root@host ~]# passwd -e test
正在终止用户 test 的密码。
passwd: 操作成功
[root@host ~]# passwd -S test
test PS 1970-01-01 0 99999 7 -1 (密码已设置,使用 SHA512 算法。) #时间变成1970年。
[root@host ~]# useradd test1
[root@host ~]# su - test1
[test1@host ~]$ su - test
密码:
您需要立即更改密码(root 强制) #切换过去时必须要更改密码,root用户切换其他用户不需要验证密码
为 test 更改 STRESS 密码。
(当前)UNIX 密码:
新的 密码:
无效的密码: 这个密码和原来的相同
新的 密码:
无效的密码: 这个密码和原来的相同
新的 密码:
passwd -d :删除密码串
[root@host ~]# passwd -S test
test PS 2020-05-06 0 99999 7 -1 (密码已设置,使用 SHA512 算法。)
[root@host ~]# passwd -d test
清除用户的密码 test。
passwd: 操作成功
[root@host ~]# passwd -S test
test NP 2020-05-06 0 99999 7 -1 (密码为空。)
[root@host ~]# su - test
上一次登录:三 5月 6 17:10:13 CST 2020pts/1 上
[test@host ~]$ su - test #此时其他用户切换到此用户不需要验证密码
上一次登录:三 5月 6 17:10:55 CST 2020pts/1 上
passwd -x:两次密码修改的最大天数
[root@host ~]# echo "123456" | passwd --stdin test
更改用户 test 的密码 。
passwd:所有的身份验证令牌已经成功更新。
[root@host ~]# passwd -x 3 test
调整用户密码老化数据test。
passwd: 操作成功
passwd -n:两次密码修改的最小天数
[root@host ~]# passwd -n 2 test
调整用户密码老化数据test。
passwd: 操作成功
passwd -w:密码过期前多少天会提醒用户
[root@host ~]# passwd -w 1 test
调整用户密码老化数据test。
passwd: 操作成功
passwd -i:密码过期多少天后会被禁用
[root@host ~]# passwd -i 4 test
调整用户密码老化数据test。
passwd: 操作成功
passwd -s:查询密码状态
[root@host ~]# passwd -S test
test PS 2020-05-06 2 3 1 4 (密码已设置,使用 SHA512 算法。)
test:用户名
PS:密码状态 (PS=密码设置,LK=密码锁定,NP=无密码)
2020-05-06 :上次密码修改的时间
2 :passwd -n --两次修改密码间隔最小2天
3 :passwd -x --两次修改密码间隔最大3天
1 :passwd -w --密码过期前1天会提醒用户更改密码
4 :passwd -i --密码过期后4天会被禁用
[root@host atime]# cat /etc/shadow
test:$6$wbC8xaR3$M.aZBpobEWM5/838Ujo1WXvkkhuYh1y.AdneYzPP2Pbees64JvkuJ6F4HuHyE8sz3P89lwR0eUU3hwKI6wrJm1:18388:2:3:1:4::
用户名:密码信息(加密后):密码修改日期(距离1970.1.1日的天数):两次修改密码最小间隔:最大间隔(即必须修改密码):过期前n天提醒用户修改密码:过期n天后必须修改密码:过期n天后账号被禁用(以1970.1.1位参考时间设置):
用法:chage [选项] 登录
选项:
-d, --lastday 最近日期 设置自1970年1月1日以来最后一次更改密码的天数。
-m, --mindays 最小天数 将两次改变密码之间相距的最小天数设为“最小天数”
-M, --maxdays 最大天数 将两次改变密码之间相距的最大天数设为“最大天数”
-I, --inactive INACITVE 过期 INACTIVE 天数后,设定密码为失效状态
-E, --expiredate 过期日期 密码到期日期
-W, --warndays 警告天数 将过期警告天数设为“警告天数”
-h, --help 显示此帮助信息并推出
-l, --list 显示帐户年龄信息
-R, --root CHROOT_DIR chroot 到的目录
[root@host ~]# useradd test01
[root@host ~]# passwd test01
更改用户 test01 的密码 。
新的 密码:
无效的密码: 密码少于 8 个字符
重新输入新的 密码:
passwd:所有的身份验证令牌已经成功更新。
chage -d :更改密码最近一次修改时间,自1970.1.1计算
[root@host ~]# chage -d 18388 test01 #自1970.1.1开始计算的天数
[root@host ~]# grep test01 /etc/shadow
test01:$6$Qi1NxTen$X6ar.uQWUQGUxRyWopNzGpyZt9PsvlnYexC1v/Cxpv2D7ZD6Z98y9ZTTkAH46lrhgPlgVlXjKm7e9rrhUNhgP.:18388:0:99999:7:::
[root@host ~]# chage -m 1 test01
[root@host ~]# grep test01 /etc/shadow
test01:$6$Qi1NxTen$X6ar.uQWUQGUxRyWopNzGpyZt9PsvlnYexC1v/Cxpv2D7ZD6Z98y9ZTTkAH46lrhgPlgVlXjKm7e9rrhUNhgP.:18388:1:99999::::
[root@host ~]# chage -M 6 test01
[root@host ~]# grep test01 /etc/shadow
test01:$6$Qi1NxTen$X6ar.uQWUQGUxRyWopNzGpyZt9PsvlnYexC1v/Cxpv2D7ZD6Z98y9ZTTkAH46lrhgPlgVlXjKm7e9rrhUNhgP.:18388:1:6::::
[root@host ~]# chage -W 3 test01
[root@host ~]# grep test01 /etc/shadow
test01:$6$Qi1NxTen$X6ar.uQWUQGUxRyWopNzGpyZt9PsvlnYexC1v/Cxpv2D7ZD6Z98y9ZTTkAH46lrhgPlgVlXjKm7e9rrhUNhgP.:18388:1:6:3:::
[root@host ~]# chage -I 2 test01
[root@host ~]# grep test01 /etc/shadow
test01:$6$Qi1NxTen$X6ar.uQWUQGUxRyWopNzGpyZt9PsvlnYexC1v/Cxpv2D7ZD6Z98y9ZTTkAH46lrhgPlgVlXjKm7e9rrhUNhgP.:18388:1:6:3:2::
[root@host ~]# chage -E "2020-12-31" test01
[root@host ~]# grep test01 /etc/shadow
test01:$6$Qi1NxTen$X6ar.uQWUQGUxRyWopNzGpyZt9PsvlnYexC1v/Cxpv2D7ZD6Z98y9ZTTkAH46lrhgPlgVlXjKm7e9rrhUNhgP.:18388:1:6:3:2:18627:
用法:gpasswd [选项] 组
选项:
-a, --add USER 向组 GROUP 中添加用户 USER
-d, --delete USER 从组 GROUP 中添加或删除用户
-h, --help 显示此帮助信息并推出
-Q, --root CHROOT_DIR 要 chroot 进的目录
-r, --delete-password remove the GROUP's password
-R, --restrict 向其成员限制访问组 GROUP
-M, --members USER,... 设置组 GROUP 的成员列表
-A, --administrators ADMIN,... 设置组的管理员列表
newgrp [-] group:临时切换指定的组为基本组
------------------------------------------------------------------------------------------------------- 返回目录