Linux 中的 chage 命令和示例
chage命令用于查看和修改用户密码过期信息。当要在有限的时间内为用户提供登录或需要不时更改登录密码时,将使用此命令。使用这个命令我们可以查看一个账户的老化信息,上次修改密码的日期,设置修改密码的时间,在一定时间后锁定一个账户等
.
chage 命令的语法如下:
句法:
chage [options] LOGIN
要查看可与 chage 命令一起使用的选项列表,请使用 help 选项
Input :
chage -h
输出 :
例子:
1. -l option : use this option to view the account aging information. In order to view the aging information of the root i am using the keyword sudo
Input :
sudo chage -l root
输出 :
2. -d option : use this option to set the last password change date to your specified date in the command. In order to change the aging information of the root i am using the keyword “sudo”. Further i am using the -l option to view the changed date.
Input :
sudo chage -d 2018-12-01 root
输出 :
3. -E option : use this option to specify the date when the account should expire. In order to change the aging information of the root i am using the keyword sudo.Further i am using the -l option to view the changed date.
Input :
sudo chage -E root
输出 :
4. -M or -m option : use this option to specify the maximum and minimum number of days between password change. In order to change the aging information of the root i am using the keyword sudo. Further i am using the -l option to view the changed period.
Input :
sudo chage -M 5 root
输出 :
5. -I option : use this option to specify the number of days the account should be inactive after its expiry. It is necessary that the user should change the password after it expires, this command is useful when the user does not login after its expiry. Even after this inactivity period if the password is not changed then the account is locked and the user should approach the admin to unlock it. In order to change the aging information of the root i am using the keyword sudo. Further I used the -l option to view the inactivity period.
Input :
sudo chage -I 5 root
输出 :
6. -W option : use this option to give prior warning before the password expires.The input given in the command is the number of days prior to the expiry date when the warning should be given .In order to change the aging information of the root i am using the keyword sudo.Further i am using the -l option to view the warning period.
Input :
sudo chage -W 2 root
输出 :