linux chage 命令介绍和使用案例
chage 命令是 Linux 系统中用于管理用户密码过期信息的工具,主要用于系统管理员控制密码策略。通过该命令,管理员可以查看和修改用户的密码有效期、最后更改日期等信息
基本语法bashchage [options] LOGIN常用选项-l:显示用户的密码和过期信息。-d LAST_DAY:设置密码最后更改的日期。-E EXPIRE_DATE:设置账户的过期日期。-M MAX_DAYS:设置密码的最大有效天数。-m MIN_DAYS:设置密码的最小有效天数。-I INACTIVE_DAYS:设置密码过期后账户的非活动天数。-W WARN_DAYS:设置在密码到期前的警告天数。命令:
root@meng:~# which chage
/usr/bin/chage
root@meng:~# chage
Usage: chage [options] LOGIN
Options:
-d, --lastday LAST_DAY set date of last password change to LAST_DAY
-E, --expiredate EXPIRE_DATE set account expiration date to EXPIRE_DATE
-h, --help display this help message and exit
-i, --iso8601 use YYYY-MM-DD when printing dates
-I, --inactive INACTIVE set password inactive after expiration
to INACTIVE
-l, --list show account aging information
-m, --mindays MIN_DAYS set minimum number of days before password
change to MIN_DAYS
-M, --maxdays MAX_DAYS set maximum number of days before password
change to MAX_DAYS
-R, --root CHROOT_DIR directory to chroot into
-W, --warndays WARN_DAYS set expiration warning days to WARN_DAYS
命令案例:
root@meng:~# id meng
uid=1000(meng) gid=1000(meng) groups=1000(meng),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),110(lxd)
root@meng:~# chage -l meng
Last password change : May 29, 2023
Password expires : never
Password inactive : never
Account expires : never
Minimum number of days between password change : 0
Maximum number of days between password change : 99999
Number of days of warning before password expires : 7