chage命令详解

 

基础命令学习目录首页html

 

原文连接:https://www.jb51.net/article/78693.htmmysql

linux chage命令简介:linux

chage命令用于密码实效管理,该是用来修改账号和密码的有效期限。它能够修改帐号和密码的有效期。对于chage命令的描述以下所示:sql

The chage command changes the number of days between password changes and the date of the last password change. This information is used by the system to determine when a user must change his/her passwordbash

命令语法:服务器

chage [options] userpost

命令参数:学习

 

参数this

描叙url

-d

指定密码最后修改日期

-E

密码到期的日期,过了这天,此帐号将不可用。0表示立刻过时,-1表示永不过时。

-h

显示帮助信息并退出

-I

密码过时后,锁定帐号的天数

-l

列出用户以及密码的有效期

-m

密码能够更改的最小天数。为零表明任什么时候候均可以更改密码。

-M

密码保持有效的最大天数。

-W

密码过时前,提早收到警告信息的天数。

 

使用示例:

1: 查看chage命令的帮助信息

[root@DB-Server ~]#man chage
[root@DB-Server ~]# info chage
[root@DB-Server ~]# chage -h
Usage: chage [options] user

Options:

-d, --lastday LAST_DAY set 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, --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 maximim number of days before password
change to MAX_DAYS
-W, --warndays WARN_DAYS set expiration warning days to WARN_DAYS

2:查看mysql用户以及密码的有效期

[root@DB-Server ~]# chage -l mysql
Last password change : Mar 26, 2015
Password expires : never
Password inactive : never
Account expires : never
Minimum number of days between password change : -1
Maximum number of days between password change : -1
Number of days of warning before password expires : -1
[root@DB-Server ~]#

3:设置mysql用户60天后密码过时,至少7天后才能修改密码,密码过时前7天开始收到告警信息。

[root@DB-Server ~]# chage -M 60 -m 7 -W 7 mysql
You have new mail in /var/spool/mail/root
[root@DB-Server ~]# chage -l mysql
Last password change : Mar 26, 2015
Password expires : May 25, 2015
Password inactive : never
Account expires : never
Minimum number of days between password change : 7
Maximum number of days between password change : 60
Number of days of warning before password expires : 7
[root@DB-Server ~]#
clip_image001

4:强制新建用户第一次登录时修改密码

[root@DB-Server home]# useradd test
[root@DB-Server home]# passwd test
Changing password for user test.
New UNIX password:
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
[root@DB-Server home]# chage -d 0 test
You have new mail in /var/spool/mail/root
[root@DB-Server home]# chage -l test
Last password change : password must be changed
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

下面给你们介绍linux chage命令

功能:修改账号和密码的有效期限

用法:chage[-l][-m mindays][-M maxdays][-I inactive][-E expiredate][-W warndays][-d lastdays]username

参数:

-l:列出用户的以及密码的有效期限
-m:修改密码的最小天数
-M:修改密码的最大天数
-I:密码过时后,锁定账号的天数
-d:指定密码最后修改的日期
-E:有效期,0表示当即过时,-1表示永不过时
-W:密码过时前,开始警告天数

 

chage

修改账号和密码的有效期限

补充说明

chage命令 是用来修改账号和密码的有效期限。

语法

chage [选项] 用户名

选项

-m:密码可更改的最小天数。为零时表明任什么时候候均可以更改密码。
-M:密码保持有效的最大天数。
-w:用户密码到期前,提早收到警告信息的天数。
-E:账号到期的日期。过了这天,此账号将不可用。
-d:上一次更改的日期。 -i:停滞时期。若是一个密码已过时这些天,那么此账号将不可用。 -l:例出当前的设置。由非特权用户来肯定他们的密码或账号什么时候过时。 

实例

能够编辑/etc/login.defs来设定几个参数,之后设置口令默认就按照参数设定为准:

PASS_MAX_DAYS   99999
PASS_MIN_DAYS   0
PASS_MIN_LEN    5
PASS_WARN_AGE   7

固然在/etc/default/useradd能够找到以下2个参数进行设置:

# useradd defaults file GROUP=100 HOME=/home INACTIVE=-1 EXPIRE= SHELL=/bin/bash SKEL=/etc/skel CREATE_MAIL_SPOOL=yes 

经过修改配置文件,能对以后新建用户起做用,而目前系统已经存在的用户,则直接用chage来配置。

个人服务器root账户密码策略信息以下:

[root@linuxde ~]# chage -l root 最近一次密码修改时间 : 3月 12, 2013 密码过时时间 :从不 密码失效时间 :从不 账户过时时间 :从不 两次改变密码之间相距的最小天数 :0 两次改变密码之间相距的最大天数 :99999 在密码过时以前警告的天数 :7 

我能够经过以下命令修改个人密码过时时间:

[root@linuxde ~]# chage -M 60 root [root@linuxde ~]# chage -l root 最近一次密码修改时间 : 3月 12, 2013 密码过时时间 : 5月 11, 2013 密码失效时间 :从不 账户过时时间 :从不 两次改变密码之间相距的最小天数 :0 两次改变密码之间相距的最大天数 :60 在密码过时以前警告的天数 :9 

而后经过以下命令设置密码失效时间:

[root@linuxde ~]# chage -I 5 root [root@linuxde ~]# chage -l root 最近一次密码修改时间 : 3月 12, 2013 密码过时时间 : 5月 11, 2013 密码失效时间 : 5月 16, 2013 账户过时时间 :从不 两次改变密码之间相距的最小天数 :0 两次改变密码之间相距的最大天数 :60 在密码过时以前警告的天数 :9 

从上述命令能够看到,在密码过时后5天,密码自动失效,这个用户将没法登录系统了。

相关文章
相关标签/搜索