029chage用户生效策略详解及定期更新用户密码
零、快速解决ops无法登录问题
chage -M -1 ops && chage -M 90 ops tr -dc '@A-Za-z0-9%_' </dev/urandom | head -c 15 > /tmp/testpass echo ops:`cat /tmp/testpass` | chpasswd
一、问题描述
测试环境tke node节点老密码失效,经常得驱逐pod还得重置密码,一是占用我大量时间,二是也影响测试环境服务;所以想把密码失效策略给永久禁止掉(尤其是测试环境)
二、查看密码有效期
[root@tke-node08-test-xx-qq-bj ~]# chage -l ops Last password change : Aug 15, 2022 Password expires : Nov 13, 2022 #今天是12月20号,所以有一、的情况出现 Password inactive : never Account expires : never Minimum number of days between password change : 0 #0表示用户可以任意时间修改他们的密码 Maximum number of days between password change : 90 #tlinux默认修改密码时间 Number of days of warning before password expires : 7
三、
#设置ops密码永久有效 chage -M -1 ops [root@tke-node08-test-kd-qq-bj ~]# chage -l ops Last password change : Aug 15, 2022 Password expires : never Password inactive : never Account expires : never Minimum number of days between password change : 0 Maximum number of days between password change : -1 #-M选项对应这一项 Number of days of warning before password expires : 7
四、处理定期更新ops密码
#!/bin/bash #定期修改ops用户的密码 grep -q ops /etc/passwd if [ $? -eq 0 ] ; then echo "ops 用户是存在的" else echo "ops用户不存在,需要新增ops用户" useradd ops fi tr -dc '@A-Za-z0-9%_' </dev/urandom | head -c 15 > /tmp/testpass echo ops:`cat /tmp/testpass` | chpasswd rm -rf /tmp/testpass #定期进行容器数据清理(删除24h以前创建的镜像缓存) docker system prune -af --filter "until=24h"