随笔 - 361,  文章 - 0,  评论 - 62,  阅读 - 160万

命令简介: 

  该命令用于密码时效管理。它可以修改账号和密码的有效期。对于chage命令的描述如下所示:

  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 password

命令语法:

  chage [options] user

命令参数:

参数

描叙

-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

 

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
复制代码

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 
复制代码
posted on   kosamino  阅读(369)  评论(0编辑  收藏  举报
编辑推荐:
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
历史上的今天:
2018-05-23 Mac下GitHub以及GitHub Desktop使用实战
2018-05-23 Homebrew简介和基本使用
2018-05-23 Mac下JDK、Maven、Tomcat、Git开发安装及环境变量配置

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示