
背景针对两种场景1.由于安全考虑需要设置密码有效期的情况比如很多公司电脑会设置三个月有效期有的也会对Linux服务器有这种要求需要设置用户密码过期时间。2.没有安全考虑且大部分机器做了互信定期密码失效会影响业务需要设置密码永不过期。1.设置用户密码过期时间1.查看admin用户密码默认情况12345678[rootlocalhost ~]# chage -l adminLast password change : Nov 24, 2022Password expires : neverPassword inactive : neverAccount expires : neverMinimum number of days between password change : 0Maximum number of days between password change : 99999Number of days of warning before password expires : 7默认永不修改的2.设置密码定期过期12345678[rootlocalhost ~]# chage -d 0 -m 0 -M 90 -W 15 admin-m#密码可更改的最小天数为0时代表任何时候都可以更改密码-M#密码保持有效的最大天数-W#用户密码到期前提前收到警告信息的天数-E#帐号到期的日期。过了这天此帐号将不可用。-d#上一次更改的日期-I#停滞时期。如果一个密码已过期这些天那么此帐号将不可用。-l#例出当前的设置。由非特权用户来确定他们的密码或帐号何时过期。3.查看admin12345678[rootlocalhost ~]# chage -l adminLast password change : Dec 02, 2022Password expires : Mar 02, 2023#密码到期时间Password inactive : neverAccount expires : neverMinimum number of days between password change : 0Maximum number of days between password change : 90Number of days of warning before password expires : 154.新开窗口登录admin会提示修改密码才可以登录123456789101112131415161718192021222324[C:\~]$sshadmin192.168.137.16Connecting to 192.168.137.16:22...Connection established.To escape tolocalshell, pressCtrlAlt].WARNING! The remote SSH server rejected X11 forwarding request.You are required to change your password immediately (administrator enforced).Authorizedusersonly. All activities may be monitored and reported.Last login: Fri Dec 2 16:53:00 2022 from 192.168.137.1WARNING: Your password has expired.You must change your password now and login again!更改用户 admin 的密码 。为 admin 更改 STRESS 密码。当前的密码新的 密码重新输入新的 密码passwd所有的身份验证令牌已经成功更新。Connection closed.Disconnected from remote host(192.168.137.16:22) at 16:53:16.修改后会断开连接用新密码再次登录成功。2.取消密码有效期改成永不过期123456789[rootlocalhost ~]# chage -M 99999 -W 7 admin[rootlocalhost ~]# chage -l adminLast password change : Dec 02, 2022Password expires : neverPassword inactive : neverAccount expires : neverMinimum number of days between password change : 0Maximum number of days between password change : 99999Number of days of warning before password expires : 7到此这篇关于Linux设置用户密码过期时间或永不过期的具体方法的文章就介绍到这了,